Reading from stdin

Luis Zarrabeitia kyrie at uh.cu
Tue Oct 7 15:56:34 EDT 2008


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').

??Is there any way to tell stdin's iterator not to buffer the input? Is it 
part of the standard file protocol?

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie



More information about the Python-list mailing list