Turn off buffering

后端 未结 4 1615

Where is the buffer in this following ... and how do I turn it off?

I am writing out to stdout in a python program like so:

for line in sys.stdin:
           


        
4条回答
  •  孤街浪徒
    2020-12-16 17:03

    The problem is in your for loop. It will wait for EOF before continuing on. You can fix it with a code like this.

    while True:
        try:
            line = sys.stdin.readline()
        except KeyboardInterrupt:
            break 
    
        if not line:
            break
    
        print line,
    

    Try this out.

提交回复
热议问题