instancemethod

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Jan 26 19:08:00 EST 2007


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:

"Not checking the return value of close() is a common but nevertheless
serious programming error. It is quite possible that errors on a previous
write(2) operation are first reported at the final close(). Not checking
the return value when closing the file may lead to silent loss of data.
This can especially be observed with NFS and with disk quota."

http://www.die.net/doc/linux/man/man2/close.2.html

I assume that the same will apply in Python.

It has to be said, however, that the error recovery shown ("pass") is
fairly pointless :-)


-- 
Steven




More information about the Python-list mailing list