This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sys.__stdout__ doco isn't discouraging enough
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: ajaksu2, georg.brandl, jvr, kbk
Priority: normal Keywords:

Created on 2005-01-05 09:18 by jvr, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg60627 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2005-01-05 09:18
sys.__stdout__ is quite often abused (two independent sightings on 
c.l.py yesterday): people use it to restore stdout instead of saving 
the previous stdout.

The real intended use for __stdout__ isn't all that clear (I keep 
wondering myself why it's there in the first place; its use case 
must be quite obscure), but more importantly I think the sys docs 
should contain a warning that __stdout__ is *not* suitable to 
restore sys.stdout after redirection.

I'd produce a patch if I knew how to better describe what 
sys.__stdout__ was *for*.
msg60628 - (view) Author: Kurt B. Kaiser (kbk) * (Python committer) Date: 2005-01-08 22:41
Logged In: YES 
user_id=149084

In IDLE it's useful for debugging:
print>>sys.__stderr__, "!!!BOO!!!"
will print a message to the console no matter what the
redirection status is.  So that's a use in addition to the
two given in the sys module docs.  Agreed that its bad
practice to use them to restore redirection, but that IMO
belongs in a tutorial, not the reference docs....
msg81512 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-09 22:49
Current docs seem to explain what __stdout__ is for:
"""
__stdin__ / __stdout__ / __stderr__

These objects contain the original values of stdin, stderr and stdout at
the start of the program. They are used during finalization, and could
be useful to restore the actual files to known working file objects in
case they have been overwritten with a broken object.
"""

Should a note of warning be added? Something like:

Explicitly saving the original IO streams and restoring them after
redirection is safer and the recommended idiom.
msg84869 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 19:10
Amended documentation in r70867.
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41402
2009-03-31 19:10:48georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg84869
2009-02-10 02:29:05pitrousetassignee: georg.brandl
nosy: + georg.brandl
2009-02-09 22:49:50ajaksu2setnosy: + ajaksu2
messages: + msg81512
versions: + Python 2.7
2005-01-05 09:18:56jvrcreate