I thought this program will echo my console input line by line:
import os, sys
for line in sys.stdin:
print line
Unfortunately it waits for EOF (Ctrl + D) and then it produces output. How should I modify my program to get output line by line?
Python 2.x:
Python 3.x:
See the documentation on
iter()with two arguments, it actually has reading from a file like this as one of the examples.