Anonymous file closing

Peter Hansen peter at
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 =
>> 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


More information about the Python-list mailing list