I frequently see python code similar to
for line in open(filename): do_something(line)
When does filename get closed with this code?>
The with part is better because it close the file afterwards. You don't even have to use readlines(). for line in file is enough.
with
readlines()
for line in file
I don't think the first one closes it.