I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:
Hence the with statement.
For Python 2.5, use
from __future__ import with_statement
(For Python 2.6 or 3.x, do nothing)
with open( "someFile", "rU" ) as aFile:
# process the file
pass
# At this point, the file was closed by the with statement.
# Bonus, it's also out of scope of the with statement,
# and eligible for GC.