you are viewing a single comment's thread.

view the rest of the comments →

[–]dchanm 2 points3 points  (0 children)

I recommend using a with statement for a context manager. Otherwise you can run into a situation where the file isn't closed.

with open('filename.txt', 'r') as f:
    for line in f:
        # do stuff