sys.stdin.readline()

Mike Maxwell maxwell at ldc.upenn.edu
Tue Aug 31 16:21:37 EDT 2004


When I invoke readline() in a for loop, why does it return a series of
one-char strings, rather than the full line?

>>> for sL in sys.stdin.readline(): print sL
...
abc
a
b
c

(I typed in 'abc', and the loop printed out 'a\nb\nc\n')

I.e. how can I make readline() wait for the newline before returning a
value?  'readline()' seems to be acting exactly like 'read()' here.

('readlines()' works fine in this context, except that it waits for
eof; I'd really rather iterate over lines in stdin as they come in)



More information about the Python-list mailing list