Redirect stdout to file
Michael P. Reilly
arcege at shore.net
Wed Jul 14 14:33:20 EDT 1999
Gaetan Corneau <Gaetan_Corneau at baan.com> wrote:
: Hello,
: I'm in Barneveld Holland right now (hey, maybe I'll go visit the famous
: Stichting Mathematisch Centrum ;) and I would like to redirect output from
: the print statement to a text file. I think a saw a message about that some
: time ago, but I can't find it right now.
: Anyone could help?
You can change sys.stdout and/or sys.stderr.
import sys # do not use from sys import stdout
sys.old_stdout = sys.stdout
sys.stdout = open('foo.txt', 'w')
-Arcege
More information about the Python-list
mailing list