I\'m running Python 2.4 in a game engine and I want to be able to turn off all prints if needed. For example I\'d like to have the prints on for a debug build, and then turn
yes, you can assign sys.stdout
to whatever you want. Create a little class with a write
method that does nothing:
class DevNull(object):
def write(self, arg):
pass
import sys
sys.stdout = DevNull()
print "this goes to nirvana!"
With the same technique you can also have your prints logged to a file by setting sys.stdout
to an opened file object.