I want to read huge text file line by line (and stop if a line with \"str\" found). How to check, if file-end is reached?
fn = \'t.log\'
f = open(fn, \'r\')
There's no need to check for EOF in python, simply do:
with open('t.ini') as f:
for line in f:
# For Python3, use print(line)
print line
if 'str' in line:
break
Why the with statement:
It is good practice to use the
withkeyword when dealing with file objects. This has the advantage that the file is properly closed after its suite finishes, even if an exception is raised on the way.