Python vs Java garbage collection?

Ype Kingma ykingma at accessforall.nl
Mon Dec 23 04:44:07 EST 2002


Eric,
Thanks,
Ype 

> 
>> Untested code:
>> 
>> def openread(fname):
>>     try:
>>         fp = open(fname)
>>         return fp.read()
>>     finally:
>>         fp.close()

> fp = open(fname)
> try:
> return fp.read()
> finally:
> fp.close()
> 
> If open throws, then the fp name will not be bound, so on the way out
> the finally clause will generate a NameError.



More information about the Python-list mailing list