On Wed, Oct 21, 2009 at 3:29 PM, Lie Ryan <[email protected]> wrote:
> 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.
Really a try/except block would actually work
def spam1():
pass
try:
spam2
except NameError:
def spam2():
pass
Because if DEBUG isn't declared you'll throw a NameError
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor