It is typically said that you should use a with statement when working with files in python, so that regardless of whether the operations on the file succeed the file will be closed. For example:
with open('somefile') as f:
# do stuff to file
instead of something like:
try:
f = open('somefile')
# do stuff to file
except Exception as e:
print 'error: %s' % e
finally:
f.close()
However, I've also heard that Python's GC will take care of it anyway, so it isn't necessary.
Is this true? If so, why is it a pattern commonly suggested?