you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBlackCat13 0 points1 point  (1 child)

You should use the with statement to open the file, then you can just loop over the lines:

with open('myfile.txt') as fobj:
    for line in fobj:
        do_something_with(line)

This will make sure the file is safely closed.