stdout
Michael Hudson
mwh21 at cam.ac.uk
Wed Jun 14 15:14:56 EDT 2000
"Michaell Taylor" <Michaell.Taylor at reis.com> writes:
> I am having a bit of trouble redirecting output from a file back to the
> terminal. I have:
>
> import sys
> f=open('c:\output.txt', 'w')
> sys.stdout=f
> blah..
> blah..
> blah..
> sys.stdout='<stdout>'
> print 'finished'
>
>
> which does not work. I've searched the docs but only see references for
> directing to files (which is helpful) but none for redirecting to a screen.
> The last two lines aren't doing the trick. Any ideas?
You need to save the original sys.stdout somewhere, eg.
oldstdout = sys.stdout
try:
f=open('c:\output.txt', 'w')
sys.stdout=f
blah....
finally:
sys.stdout = oldstdout
HTH,
Michael
--
On the other hand, the following areas are subject to boycott
in reaction to the rampant impurity of design or execution, as
determined after a period of study, in no particular order:
... http://www.naggum.no/profile.html
More information about the Python-list
mailing list