to close or not to close?

Grant Griffin g2 at seebelow.org
Tue Aug 1 13:44:37 EDT 2000


In article <slrn8oc120.8dh.scarblac-spamtrap at flits104-37.flits.rug.nl>,
scarblac-spamtrap at pino.selwerd.nl says...
>
>Grant Griffin wrote in comp.lang.python:
>> Forgive me if this is a FAQ, but is it considered good Python form to close a
>>file whose variable is just about to go out of scope (and thus be automatically
>> closed)?  Or should one just omit that?
>
>Close it. Explicit is better than implicit, and you don't rely on the
>__del__ method being called - for instance, in JPython the file wouldn't be
>closed (afaik).
>

Thanks, Remco (and to others)--that helps.

Coincidentally, when reading about Perl6 today, I ran onto this at
http://www.perl.com/pub/2000/07/perl6.html:

"Every few months, someone suggests replacing Perl's garbage collector with a
more modern one, but there are always objections from people who have written
code that assumes that the garbage collector will always be reference-count
based and that it can control when objects will be destructed."

(explict-is-better-than-implicit-even-in-perl-<wink>)-ly y'rs,

=g2

_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com




More information about the Python-list mailing list