file.close()

Ulrich Petri ulope at gmx.de
Fri Jul 25 03:37:46 EDT 2003


"Francois Pinard" <pinard at iro.umontreal.ca> schrieb im Newsbeitrag
news:mailman.1059052897.16526.python-list at python.org...
> [Bryan]
>
> > I'm curious to know how others handle the closing of files.  [...] I'm
> > aware that files will automatically be closed when the process exits.
>
> For one, I systematically avoid cluttering my code with unneeded `close'.
> The advantages are simplicity and legibility, both utterly important to
me.
>
> However, I do understand that if I ever have to move a Python script
> to Jython, I will have to revise my scripts for adding the clutter I am
> sparing today.  I'm quite accepting to do that revision if this occurs.
> Until then, I prefer keeping my scripts as neat as possible.
>
> For me, explicitely closing a file, for which the only reference is about
> to disappear through function exiting, would be very similar to using
> `del' on any variable I happened to use in that function: gross
overkill...
>
> The only reason to call `close' explicitly is when there is a need to
close
> prematurely.  Absolutely no doubt that such needs exist at times.  But
> closing all the time "just in case" is symptomatic of unsure programming.
> Or else, it is using Python while still thinking in other languages.
>

fire up your python and type: "import this" read the output and rethink your
codint techniques

Ciao Ulrich






More information about the Python-list mailing list