instancemethod

Gabriel Genellina gagsl-py at yahoo.com.ar
Fri Jan 26 23:03:50 EST 2007


"Steven D'Aprano" <steve at REMOVE.THIS.cybersource.com.au> escribió en el 
mensaje 
news:pan.2007.01.27.00.07.59.387012 at REMOVE.THIS.cybersource.com.au...

> On Fri, 26 Jan 2007 17:25:37 +0100, Bruno Desthuilliers wrote:
>>>    def __del__(self):
>>>        try:
>>>            self.close()
>>>        finally:
>>>            pass
>>>        except:
>>>            pass
>>
>> The finally clause is useless here.
>
> In principle, closing a file could raise an exception. I've never seen it
> happen, but it could. From the Linux man pages: [...]
> I assume that the same will apply in Python.

Note that he said that the *finally* clause were useless (and I'd say so, 
too), not the *except* clause.
And yes, in Python it is checked - when the close method was called 
explicitely, an exception is raised; when called when the object is garbage 
collected, a message is printed on sys.stderr

> It has to be said, however, that the error recovery shown ("pass") is
> fairly pointless :-)
Only supresses the message on sys.stderr - exceptions raised on __del__ are 
never propagated.

-- 
Gabriel Genellina 





More information about the Python-list mailing list