redirecting stderr

Michele Simionato michele.simionato at
Thu Nov 25 13:10:29 CET 2004

Maybe it is something obvious, but what is going on with this code?

import sys
myerr = file("myerr.txt", "w")
sys.stderr = myerr
    raise Exception, "some error"
    sys.stderr = sys.__stderr__

I would expect the error message to be written into "myerr.txt", instead
it is displayed on the console, on regular stderr (?) and "myerr.txt" is
empty. I guess I misunderstood something ...

                  Michele Simionato

More information about the Python-list mailing list