On 2010-08-11, Tim Harig <user...@ilthio.net> wrote:
> On 2010-08-11, RG <rnospa...@flownet.com> wrote:
>> When stdin is not a tty, Python seems to buffer all the input through 
>> EOF before processing any of it:
>>
>> [...@mickey:~]$ cat | python
>> print 123
>> print 456 <hit ctrl-D here>
>> 123
>> 456
>>
>> Is there a way to get Python to process input line-by-line the way it 
>> does when stdin is a TTY even when stdin is not a TTY?
>
> It would be much better to know the overall purpose of what you are trying
> to achieve.  There are may be better ways (ie, sockets) depending what you
> are trying to do.  Knowing your target platform would also be helpful.
>
> For the python interpeter itself, you can can get interactive behavior by
> invoking it with the -i option.

If you're talking about unbuffered stdin/stdout, the option is -u.

I don't really see how the -i option is relevent -- it causes the
interpreter to go into interactive mode after running the script.

> If you want to handle stdin a single line at a time from inside of your
> program, you can access it using sys.stdin.readline().

That doesn't have any effect on stdin buffering.

-- 
Grant Edwards               grant.b.edwards        Yow! ... I want to perform
                                  at               cranial activities with
                              gmail.com            Tuesday Weld!!
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to