Avoiding Buffering in a Python File Library

I saw this question asked here, but the answers received did not work in my case and were marked as duplicates.

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.

+5
source share
1 answer

, FileInput(bufsize=1). file.readlines() " , , ". , , .

with fileinput.input(bufsize=1) as f:
    for line in f:
        print("One line in, one line out!")
+5

All Articles