grante at visi.com
Tue Aug 31 22:29:25 CEST 2004
On 2004-08-31, Mike Maxwell <maxwell at ldc.upenn.edu> wrote:
> 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
> (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
> 'readline()' seems to be acting exactly like 'read()' here.
What you want is:
s = sys.stdin.readline()
if not s:
Grant Edwards grante Yow! .. I see TOILET
More information about the Python-list