What worked for me was simply setting FileInput(bufsize=1)
. The file.readlines()
documentation does state "The optional size argument, if given, is an approximate bound on the total number of bytes in the lines returned." In practice, I get exactly one new line every time rather than having to fill a buffer.
with fileinput.input(bufsize=1) as f:
for line in f:
print("One line in, one line out!")