Terry J. Reedy added the comment:

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__.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17838>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to