I was under the impression that file objects are immediately closed when their reference counts hit 0, hence the line:
foo = open('foo').read()
would get you the file's contents and immediately close the file. However, after reading the answer to http://stackoverflow.com/questions/1832528/is-close-necessary-when-using-iterator-on-a-python-file-object I get the impression that this does not happen, and that calling .close()
on a file object is always necessary.
Does the line above do what I think it's doing and even if it does, is it the Pythonic thing to do?