[Python-Dev] [PEP 214] FW: sys.stndout syntax

Tim Peters tim_one@email.msn.com
2000年8月18日 17:18:56 -0400


For those of you who stopped reading comp.lang.python, note that this is
*typical* of the advice users get in the absence of syntactic "print" sugar.
it's-not-exactly-intuitive-that-a-"print"-stmt-isn't-meant-to-
 do-output<wink>-ly y'rs - tim
-----Original Message-----
From: python-list-admin@python.org
[mailto:python-list-admin@python.org]On Behalf Of Jeff Kunce
Sent: Friday, August 18, 2000 3:41 PM
To: python-list@python.org
Subject: Re: sys.stndout syntax
> on win32, to get printed output to a file i use
> >>> sys.stndout = open('file.txt', 'w')
> how do i get it to go back to the command line

#Here is the specific solution for those who remember the secret password:
sys.stdout = open('file.txt', 'w')
print 'this is written to file.txt'
sys.stdout.close()
sys.stdout = sys.__stdout__
print 'this is written to console'
#Here is the general solution if you can't be bothered with remembering
secret passwords:
original_stdout = sys.stdout
sys.stdout = open('file.txt', 'w')
print 'this is written to file.txt'
sys.stdout.close()
sys.stdout = original_stdout
print 'this is written to console'
 --Jeff
--
http://www.python.org/mailman/listinfo/python-list

AltStyle によって変換されたページ (->オリジナル) /