'for l in sys.stdin' at interactive prompt (WAS: Re: sys.stdin.readline())

Steven Bethard steven.bethard at gmail.com
Tue Aug 31 17:29:51 EDT 2004


Hallvard B Furuseth <h.b.furuseth <at> usit.uio.no> writes:
> Or in newer Pythons, simply `for sL in sys.stdin: print sL'.

This doesn't work for me in the interactive shell:

Python 2.4a2 (#55, Aug  5 2004, 11:42:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for l in sys.stdin:
...     print repr(l)
...
A
B
C
D
^Z
'A\n'
'B\n'
'C\n'
'D\n'

Note that I don't get output until I hit ^Z (this is, obviously, a Windows 
box).  I tried starting Python with the -u option too, and I still get this 
result.  Is there any way to make 'for l in sys.stdin' work the way you 
suggest it does at an interactive prompt?

Steve




More information about the Python-list mailing list