<br><br><div class="gmail_quote">On Wed, Oct 21, 2009 at 3:29 PM, Lie Ryan <span dir="ltr">&lt;<a href="mailto:lie.1296@gmail.com">lie.1296@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">Lizhi Yang wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there anything similar to ifdef statement in C or C++ in python?<br>
</blockquote>
<br></div>
Not really, but python&#39;s regular if can be used for a similar purpose:<br>
<br>
DEBUG = True<br>
<br>
if DEBUG:<br>
    import logging<br>
    def foo():<br>
        # debug version<br>
else:<br>
    def foo():<br>
        # normal version<br>
<br>
def main():<br>
    foo()<br>
<br>
if __name__ == &#39;__main__&#39;:<br>
    main()<br>
<br>
or something like that.</blockquote><div><br></div><div>Really a try/except block would actually work</div><div><br></div><div>def spam1():</div><div>    pass</div><div><br></div><div>try:</div><div>   spam2</div><div>except NameError:</div>

<div>   def spam2():</div><div>       pass</div><div><br></div><div>Because if DEBUG isn&#39;t declared you&#39;ll throw a NameError</div></div>