debugging code

Diez B. Roggisch deetsNOSPAM at web.de
Tue Apr 27 16:01:40 EDT 2004


beliavsky at aol.com wrote:

> If I have some debugging code in a Python program (mostly print
> statements) and I want to turn it "off", two obvious methods are to
> (1) comment out the code
> (2) set a logical 'debug' variable at the beginning and use it to
> conditionally run the debugging code.
> 
> Is there a better way? Some other languages have conditional
> compilation. (I don't know if that is better or worse). What is the
> "best" way to maintain "production" and "debugging" versions of a
> Python program at the same time, preferably in the same file?

Since 2.3, python features a log4j-like logging api - look in the modules
doc for 'logging'. It uses different levels of logging that can be set so
that the output gets suppressed if the level is below the configured one.

A preprocessor variant doesn't exist.
 
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list