sys.stdin.readline()

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Tue Aug 31 17:10:00 EDT 2004


Mike Maxwell 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

It does return a full line.  *One* line.  Then your loop iterates
over the characters in that line.

Try `for sL in sys.stdin.xreadlines(): print sL'.
Or in newer Pythons, simply `for sL in sys.stdin: print sL'.

-- 
Hallvard



More information about the Python-list mailing list