At the beginning of my python program I have the following line:
sys.stdout = open('stdout_file', 'w')
Halfway through my program I would like to set stdout back to the normal stdout. How do I do this?
At the beginning of my python program I have the following line:
sys.stdout = open('stdout_file', 'w')
Halfway through my program I would like to set stdout back to the normal stdout. How do I do this?
The original stdout
can be accessed as sys.__stdout__
. This is documented.
The same holds for stderr, of course. At the end, these lines are needed to get the original streams.
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__