Reading from sys.stdin reads the whole file in

Chris Angelico rosuav at gmail.com
Wed Aug 27 02:45:29 EDT 2014


On Wed, Aug 27, 2014 at 4:37 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, 27 Aug 2014 08:29:20 +0300, Marko Rauhamaa wrote:
>
>> Try flushing after each print.
>
> Doesn't help.

It does, but insufficiently. If slurp.py is run under Py3, it works
fine; or take Naoki's suggestion (although without the parens):

import sys
import time

for line in iter(sys.stdin.readline, ''):
        print "Time of input:", time.ctime(), line
        sys.stdin.flush()
        sys.stdout.flush()

Then it works.

ChrisA



More information about the Python-list mailing list