Reading from stdin

Luis Zarrabeitia kyrie at uh.cu
Tue Oct 7 20:13:15 EDT 2008


On Tuesday 07 October 2008 05:33:18 pm George Sakkis wrote:
> Not an answer to your actual question, but you can keep the 'for' loop
> instead of rewriting it with 'while' using the iter(function,
> sentinel) idiom:
>
> for line in iter(sys.stdin.readline, ""):
>     print "You said!", line

You're right, it's not an answer to my actual question, but I had completely 
forgotten about the 'sentinel' idiom. Many thanks... I was trying to do it 
with 'itertools', obviously with no luck.

The question still stands (how to turn off the buffering), but this is a nice 
workaround until it gets answered.

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