Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - reset stdout to normal, after previously redirecting it to a file

Tags:

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?

like image 895
tadasajon Avatar asked Jan 09 '13 19:01

tadasajon


People also ask

How do you define stdout in python?

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.


1 Answers

The original stdout can be accessed as sys.__stdout__. This is documented.

like image 179
BrenBarn Avatar answered Oct 22 '22 17:10

BrenBarn