Caleb Hattingh wrote:

Peter

Yes, you can even write

f = open("data.txt")
for line in f:
    # do stuff with line
f.close()

This has the additional benefit of not slurping in the entire file at once.

Is there disk access on every iteration? I'm guessing yes? It shouldn't be an issue in the vast majority of cases, but I'm naturally curious :)

Disk access should be buffered, possibly both at the C-runtime level and at the file-iterator level (though I couldn't swear to that). I'm sure that the C-level buffering happens, though.


Jeff Shannon
Technician/Programmer
Credit International

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to