Anonymous file closing

Peter Hansen peter at engcorp.com
Mon Jun 14 14:55:09 CEST 2004


Sergey Krushinsky wrote:

> Peter Hansen wrote:
> 
>> Duncan's response says it all, but here's the solution
>> if you don't like the uncertainty inherent in the above:
>>
>> f = open(filename, 'r')
>> try:
>>     text = f.read()
>> finally:
>>     f.close()
>>
> But the uncertainty remains in case of an anonymous file, doesn't it?

Uh, yeah...  of course!  Duncan posted code with uncertainty,
and I showed what one must change to make it certain (or less
uncertain, after reading Tim Peters' comment).  How that would
change the original case with the anonymous file in any way
I just can't imagine.  (Clearly I'm missing something, or you
are...)

-Peter



More information about the Python-list mailing list