[Tutor] reading from stdin

Sean Perry shaleh at speakeasy.net
Wed Mar 2 00:01:53 CET 2005


jfouhy at paradise.net.nz wrote:
> If I do:
> 
> $ ./produce.py | ./read.py
> 
> I get nothing for ten seconds, then I get the numbers 0 through 9, one per line.
> 
> What am I missing?
> 

 From the python man page:
-u
     Force stdin, stdout and stderr to be totally unbuffered. On systems 
where it matters, also put stdin, stdout and stderr in binary mode. Note 
that there is internal buffering in xreadlines(), readlines() and 
file-object iterators ("for line in sys.stdin") which is not influenced 
by this option. To work around this, you will want to use 
"sys.stdin.readline()" inside a "while 1:" loop.


More information about the Tutor mailing list