
[From a mail in idle-dev - dropped idle-dev and all CCs] [idle-dev poster]
[Guido]
I admit that I first became aware of sys.__stdout__ after seeing this exact same idiom in other peoples code. I always assumed that this is _exactly_ what sys.__stdout__ was to be used for! The following examples exist: * Tools/unicode/makeunicodedata.py - exactly the idiom you despise. * Tools/il8n/pygettext.py - ditto * Tools/idle/PyParse.py - disabled, debugging output function - presumably to get around sys.stdout redirection - but this sounds suspect as an idiom to me too! So what _is_ it intended for? Mark.

"MH" == Mark Hammond <MarkH@ActiveState.com> writes:
MH> * Tools/il8n/pygettext.py That's embarassing. ;) Here's a patch, but I'm not going to check it in because I think a /much/ better idiom to adopt is to use extended print instead. I need to make some updates to pygettext.py soon, so I'll probably just 2.0-ify it at the same time. -Barry -------------------- snip snip -------------------- Index: pygettext.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/i18n/pygettext.py,v retrieving revision 1.9 diff -u -r1.9 pygettext.py --- pygettext.py 2000/05/02 19:28:30 1.9 +++ pygettext.py 2000/10/26 00:16:22 @@ -283,6 +283,7 @@ options = self.__options timestamp = time.ctime(time.time()) # common header + stdout = sys.stdout try: sys.stdout = fp # The time stamp in the header doesn't have the same format @@ -314,7 +315,7 @@ print 'msgid', normalize(k) print 'msgstr ""\n' finally: - sys.stdout = sys.__stdout__ + sys.stdout = stdout def main():

Mark Hammond writes:
* Tools/unicode/makeunicodedata.py - exactly the idiom you despise. * Tools/il8n/pygettext.py - ditto
I've just fixed these two; too bad checkin messages aren't getting sent. ;(
I've left this one for someone with a good idea about what to do about it. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs Team Member

Don't touch it! This one is needed because at this point sys.stdout and sys.stderr are redirected to a window where you don't want the parser debug output to show up. (I mentioned this example in my previous post.) --Guido van Rossum (home page: http://www.python.org/~guido/)

So what _is_ it intended for?
Example: IDLE redirects sys.stderr so that it gets displayed in the Python Shell window with a different text color. But occasionally I need to debug IDLE and the bug is in the text drawing. Then it's nice if I can write to __stderr__, which goes to the console. Or suppose I'm in a regular interactive session and I've managed to screw myself by assigning a bogus file object to sys.stdout (it happens :-). If I know that, I can type sys.stdout = sys.__stdout__ at the >>> prompt and save myself -- so I don't have to restart the session and perhaps lose valuable data. --Guido van Rossum (home page: http://www.python.org/~guido/)

"MH" == Mark Hammond <MarkH@ActiveState.com> writes:
MH> * Tools/il8n/pygettext.py That's embarassing. ;) Here's a patch, but I'm not going to check it in because I think a /much/ better idiom to adopt is to use extended print instead. I need to make some updates to pygettext.py soon, so I'll probably just 2.0-ify it at the same time. -Barry -------------------- snip snip -------------------- Index: pygettext.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/i18n/pygettext.py,v retrieving revision 1.9 diff -u -r1.9 pygettext.py --- pygettext.py 2000/05/02 19:28:30 1.9 +++ pygettext.py 2000/10/26 00:16:22 @@ -283,6 +283,7 @@ options = self.__options timestamp = time.ctime(time.time()) # common header + stdout = sys.stdout try: sys.stdout = fp # The time stamp in the header doesn't have the same format @@ -314,7 +315,7 @@ print 'msgid', normalize(k) print 'msgstr ""\n' finally: - sys.stdout = sys.__stdout__ + sys.stdout = stdout def main():

Mark Hammond writes:
* Tools/unicode/makeunicodedata.py - exactly the idiom you despise. * Tools/il8n/pygettext.py - ditto
I've just fixed these two; too bad checkin messages aren't getting sent. ;(
I've left this one for someone with a good idea about what to do about it. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs Team Member

Don't touch it! This one is needed because at this point sys.stdout and sys.stderr are redirected to a window where you don't want the parser debug output to show up. (I mentioned this example in my previous post.) --Guido van Rossum (home page: http://www.python.org/~guido/)

So what _is_ it intended for?
Example: IDLE redirects sys.stderr so that it gets displayed in the Python Shell window with a different text color. But occasionally I need to debug IDLE and the bug is in the text drawing. Then it's nice if I can write to __stderr__, which goes to the console. Or suppose I'm in a regular interactive session and I've managed to screw myself by assigning a bogus file object to sys.stdout (it happens :-). If I know that, I can type sys.stdout = sys.__stdout__ at the >>> prompt and save myself -- so I don't have to restart the session and perhaps lose valuable data. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (6)
-
barry@wooz.org
-
Fred L. Drake, Jr.
-
Fredrik Lundh
-
Gordon McMillan
-
Guido van Rossum
-
Mark Hammond