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.

Author terry.reedy
Recipients Guilherme.Simões, Todd.Rovito, roger.serwy, terry.reedy
Date 2013-04-25.11:29:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366889399.54.0.0556022419991.issue17838@psf.upfronthosting.co.za>
In-reply-to
Content
Once again, what system and version? The Idle user process is different on *nix and Windows -- python.exe versus pythonw.exe. In normal interactive mode, the interpreter continues to take statements from the console, which seems to be sys.__stdin__, after redirection. Sys.stdin is only used for input() statements and direct sys.stdin reads.

Python 3.3.1 (v3.3.1:d9893d13c628, Apr  6 2013, ...
>>> import sys
>>> sys.__stdin__
<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp437'>
>>> sys.stdin = open('c:/python/mypy/tem.py')
>>> sys.stdin
<_io.TextIOWrapper name='c:/python/mypy/tem.py' mode='r' encoding='cp1252'>
>>> input()
'a, b = 1, 2'
>>> input()
'print("{a} apple and {b} bananas".format(**locals()))'
# These are the 'current' first two lines of the file.
>>> sys.__stdin__
<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp437'>

With Idle, at least on Windows, sys.__stdin__ is None. If sys.stdin is the only reference to PseudoInputFile, rebinding leads to closure. With no connection to the Shell window, it would be impossible to send statements.

>>> import sys
>>> sys.stdin
<idlelib.PyShell.PseudoInputFile object at 0x0000000002CD8780>
>>> sys.__stdin__
>>> 

However, with 3.3.1 on Windows, I do not reproduce the problem.
>>> sys.stdin = open('c:/python/mypy/tem.py')
>>> sys.stdin
<_io.TextIOWrapper name='c:/python/mypy/tem.py' mode='r' encoding='cp1252'>
>>> input()
'a, b = 1, 2'
>>> input()
'print("{a} apple and {b} bananas".format(**locals()))'

So pythonw.exe seems to keep a reference other than either .stdin or .__stdin__.
History
Date User Action Args
2013-04-25 11:29:59terry.reedysetrecipients: + terry.reedy, roger.serwy, Todd.Rovito, Guilherme.Simões
2013-04-25 11:29:59terry.reedysetmessageid: <1366889399.54.0.0556022419991.issue17838@psf.upfronthosting.co.za>
2013-04-25 11:29:59terry.reedylinkissue17838 messages
2013-04-25 11:29:59terry.reedycreate