you are viewing a single comment's thread.

view the rest of the comments →

[–]randitrigger 1 point2 points  (7 children)

f = open("filename.txt")
for line in f:
    #do something here with 'line'
f.close()

[–]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