Styling Temporary Code

Emile van Sebille emile at fenx.com
Sat Jun 3 09:02:25 EDT 2000


Note that if you put additional tests on the
if __debug__ line, everything still gets
optimized out, allowing related debug code
to be effectively turned on or off.

debugWatchList = ["Mod1","Mod2","NewMod"]

if __debug__ and "ThisModName" in debugWatchList:
  print "InDebugCode"

---or---

class Test:
 def __init__(self, watchlist):
  self.data = watchlist
 def __call__(self, target):
  return target in self.data

debugWatch = Test(["Mod1", "Mod2", "NewMod"])

if __debug__ and debugWatch("NewMod"):
 print "InDebugCode"


Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: Aahz Maruch <aahz at netcom.com>

<snip>

> One person already suggested that you use assert.  Note
that in Python
> 1.5.2 and later, you can turn off assert by setting the
PYTHONOPTIMIZE
> variable in addition to using -O on the command line.  You
can also
> express more complicated code with
>
> if __debug__:
>   ....
>
> Both assert and "if __debug__" get optimized out with
optimization
> turned on.
> --
>                       --- Aahz (Copyright 2000 by
aahz at netcom.com)
>
> Androgynous poly kinky vanilla queer het    <*>
http://www.rahul.net/aahz/
> Hugs and backrubs -- I break Rule 6
>
> Have you coined a word today?  --Aahz
> --
> http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list