Re:Don’t Slurp: How to Read Files in Python
by gcr on Friday September 27, 2013 @06:02PM
(#6459845)
Yes, this is essentially looping over successive calls to file.readline()
[ Parent
| on HN ]
Re:Don’t Slurp: How to Read Files in Python
by tjgq on Friday September 27, 2013 @08:11PM
(#6460325)
With at least one small (and usually irrelevant) difference: "for line in file" has its own internal buffering which cannot be turned off with python -u.
I learned this the hard way when debugging a Python script that read from tail -f output...
Re:Don’t Slurp: How to Read Files in Python
by gcr on Saturday September 28, 2013 @06:59PM
(#6463428)
I thought a function that reads a line from a file would read the entire line and block until doing so. How would turning off line buffering change that? Do you expect 'for line in file' to yield as many bytes as is available if a full line can't be read yet?