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?
A built-in file object that is analogous to the interpreter's standard output stream in Python. stdout is used to display output directly to the screen console. Output can be of any form, it can be output from a print statement, an expression statement, and even a prompt direct for input.
The original stdout
can be accessed as sys.__stdout__
. This is documented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With