I saw this question asked here, but the answers received did not work in my case and were marked as duplicates.
python -u
stdin
sys.stdin = sys.stdin.detach()
ValueError: underlying buffer has been detached
FileInput(openhook=hook_nobuf)
open(buffering=0)
I dug up the source code ( /usr/lib/python3.2/fileinput.py) and saw what was readlines(bufsize)used internally to load the buffer. No sink or other piping shuntigans.
/usr/lib/python3.2/fileinput.py
readlines(bufsize)
, FileInput(bufsize=1). file.readlines() " , , ". , , .
FileInput(bufsize=1)
file.readlines()
with fileinput.input(bufsize=1) as f: for line in f: print("One line in, one line out!")