Debugging Python ?

logistix at cathoderaymission.net logistix at cathoderaymission.net
Tue Jul 29 00:13:43 EDT 2003


pedro.werneck at bol.com.br (Pedro Werneck) wrote in message news:<ef72fb2b.0307281449.6b144be7 at posting.google.com>...
> I use:
> 
> if __debug__: print "bla, bla, bla..."
> 
> And I was just wondering if it's legal to define a "print" function...
> isn't print a keyword ?

Instead of defining "print" you can assign a custom class to
sys.stdout.  Then all the print statements get automagically
redirected.:

if __debug__:
    class newStdout:
        def write(self,string):
            print string
else:
    class newStdout:
        def write(self,string):
            pass

import sys
sys.stdout = newStdout()




More information about the Python-list mailing list