file.close()
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Thu Jul 24 22:21:35 EDT 2003
> From: Francois Pinard [mailto:pinard at iro.umontreal.ca]
>
> 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.
No - it is writing portable code that conforms to the Python language documentation. But we've had this argument before.
Even in CPython, closing before a reference goes away is vital in many cases. The simplest example is writing to a file, then reading it. You don't always want to keep a copy of the data in memory - it's often a lot better to stream the data, even if you have to do it multiple times.
Tim Delaney
More information about the Python-list
mailing list