I understand that the with
block automatically calls close()
after you exit the block, and that it is often used to make sure one doesn't forget to close a file.
It seems that there is no technical difference between
with open(file, 'r+') as f:
do_things(f)
and
f = open(file, 'r+')
do_things(f)
f.close()
Is one way more Pythonic than the other? Which should I use in my code?