作者soeasyright (SOEASYRIGHT)
看板Python
标题[问题] 类似c的#ifdef
时间Fri May 30 01:36:31 2014
请问python 有类似 C #ifdef debug_on
这种开启的方法吗? 还是要换个思维?
#ifdef debug_on
#define LOG(...) do{}while(0)
#else
#define LOG(...) print(...)
#endif
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.127.81.37
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1401384994.A.05F.html
※ 编辑: soeasyright (59.127.81.37), 05/30/2014 01:36:52
1F:→ gozule:把debug_on当做是一个变数,在程式里面用if判断 05/30 01:44
2F:→ soeasyright:我发现问错了 应该是要问#define 这样转变的才对Orz 05/30 02:01
3F:→ soeasyright:! 我好像懂了 05/30 02:03
def log(*i,**j)
if debug_on:
print(*i,**j)
else:
pass
※ 编辑: soeasyright (59.127.81.37), 05/30/2014 02:07:42
4F:→ jcfrank:Python 的method不是可以被redefine吗? 05/30 02:09
5F:推 walelile:logging? 05/30 02:15
7F:→ soeasyright:喔喔!!! 新手上路 谢谢大家 正在看logging 再次谢谢 05/30 02:21