Intercept and Tag STDOUT values
MornIHATESPAMThdr at NOSPAMverizon.net
Wed Oct 13 05:55:12 CEST 2004
How can I redirect and tag sys.stdout values. I tried creating a class
module that saved the old stdout and replaced it, but I can't seem to figure
out how to do such.
Here is what I got...
class cStdOutRedirect :
stdOld = ""
def __main__(self) :
stdOld = sys.stdout
sys.stdout = self
def write(self,str) :
stdOld.write("REDIRECTED OUTPUT: " + str)
def close(self) :
sys.stdout = stdOld
then in the main code...
c = cStdOutRedirect()
print "hello world"
I'm in a high school Python class and this is well beyond where the
instructor is now and he isn't too fond of answering advanced questions. I
have programmed in quite a few other languages, so I understand quite a bit
More information about the Python-list