Why no open(f, "w").write()?

Grant Edwards grante at visi.com
Wed May 29 22:13:56 EDT 2002


In article <mailman.1022707669.6727.python-list at python.org>, Gary Herron wrote:

>> yes, but can you disagree with the statement that it is bad programming
>> practice.  I sure can't.
> 
> Here's why its a bad practice:
> 
> The question is: When does the file get closed?

Sometime before the program exits.

> The expectation is that the file object will be garbage collected
> immediately after the statement is executed (since that's when its ref
> count goes to zero), and that this will force the file to be closed.

If that's the expectation, then I agree that it's bad practice.
If the expectation is that the file will be closed by the time
the program has terminated, then is it still bad practice?

Probably so...

-- 
Grant Edwards                   grante             Yow!  I'm into SOFTWARE!
                                  at               
                               visi.com            



More information about the Python-list mailing list