[Tutor] ifdef in python

Lie Ryan lie.1296 at gmail.com
Wed Oct 21 22:29:37 CEST 2009


Lizhi Yang wrote:
> Is there anything similar to ifdef statement in C or C++ in python?

Not really, but python's regular if can be used for a similar purpose:

DEBUG = True

if DEBUG:
     import logging
     def foo():
         # debug version
else:
     def foo():
         # normal version

def main():
     foo()

if __name__ == '__main__':
     main()

or something like that.



More information about the Tutor mailing list