Grant Edwards grante at
Tue Aug 31 22:29:25 CEST 2004

On 2004-08-31, Mike Maxwell <maxwell at> 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
> ...
> 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?

It is.

> 'readline()' seems to be acting exactly like 'read()' here.

Sort of.

What you want is:

import sys
while True:
    s = sys.stdin.readline()
    if not s:
    print s
Grant Edwards                   grante             Yow!  .. I see TOILET
                                  at               SEATS...

More information about the Python-list mailing list