file closing

Colin Brown cbrown at metservice.com
Wed May 21 21:14:05 EDT 2003


After reading replies to a previous thread about potential loss of data
when not closing a file after writing it, I got to wonder if the following
two codes snippets are functionally the same after all:

f = file('test.dat','w')
f.write(chr(0)*1000000)
f.close()

file('test.dat','w').write(chr(0)*1000000)

Does the first case explicitly close the file where the second one relies on
garbage collection?

Colin Brown
PyNZ







More information about the Python-list mailing list