Isn't it better to use if __debug__: I thought such an if statement always evaluated to False when the python program was run in OPTIMIZED (-o) mode?
Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- On Wed, 10/21/09, Wayne <[email protected]> wrote: > From: Wayne <[email protected]> > Subject: Re: [Tutor] ifdef in python > To: "Lie Ryan" <[email protected]> > Cc: [email protected] > Date: Wednesday, October 21, 2009, 11:37 PM > > > 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: spam2except > NameError: > > def spam2(): > pass > Because if DEBUG isn't declared you'll > throw a NameError > > -----Inline Attachment Follows----- > > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
