I need to read a large file, line by line. Lets say that file has more than 5GB and I need to read each line, but obviously I do not want to use
f = (line for line in open("log.txt").xreadlines()) # how much is loaded in memory?
I provided this answer because Keith's, while succinct, doesn't close the file explicitly
with open("log.txt") as infile: for line in infile: do_something_with(line)