Reading from stdin

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Oct 7 17:12:28 EDT 2008


In message <mailman.2148.1223409399.3487.python-list at python.org>, Luis
Zarrabeitia wrote:

> I have a problem with this piece of code:
> 
> ====
> import sys
> for line in sys.stdin:
>     print "You said!", line
> ====
> 
> Namely, it seems that the stdin buffers the input, so there is no reply
> until a huge amount of text has bin written. The iterator returned by
> xreadlines has the same behavior.
> 
> The stdin.readline() function doesn't share that behaviour (it returns as
> soon as I hit 'enter').

Perhaps line-buffering simply doesn't apply when you use a file object as an
iterator.



More information about the Python-list mailing list