Don't use sys.__stdout__ in examples.

This commit is contained in:
Guido van Rossum 2000-10-27 10:25:44 +00:00
parent 8a352d1e6c
commit 91c2029e89
1 changed files with 10 additions and 5 deletions

View File

@ -71,11 +71,12 @@ Justification
method, but it can be rebound to redirect output to files other
than specifically standard output. A typical idiom is
sys.stdout = mylogfile
try:
print 'this message goes to my log file'
finally:
sys.stdout = sys.__stdout__
save_stdout = sys.stdout
try:
sys.stdout = mylogfile
print 'this message goes to my log file'
finally:
sys.stdout = save_stdout
The problem with this approach is that the binding is global, and
so affects every statement inside the try: clause. For example,
@ -96,6 +97,8 @@ Reference Implementation
top of the stack and use it instead of sys.stdout as the output
stream.
(This reference implementation has been adopted in Python 2.0.)
Alternative Approaches
@ -349,6 +352,8 @@ More Justification by the BDFL
print >> file, i, 'x', j, '=', i*j
print >> file
[XXX this needs more justification, and a section of its own]
References