file.close()

Erik Max Francis max at alcyone.com
Wed Jul 23 23:29:27 EDT 2003


Bryan wrote:

> which explicitly closes f1 & f2
> any exceptions opening f1 or f2 is handled outside of this structure
> or is
> allowed to fall out of the program.  i'm aware that files will
> automatically
> be closed when the process exits.  i'm just curious how others do this
> for
> small scripts and larger programs.  is what i'm doing is overkill?

No, not at all; it's safe and portable.  Python the language does not
specify when objects get reclaimed, although CPython the implementation
does it promptly.  Use of external resources -- which should be released
as soon as you're done with them -- are best done in try/finally
clauses.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ It is fatal to enter any war without the will to win it.
\__/  Douglas MacArthur




More information about the Python-list mailing list