Dynamically change __del__

2010-04-30 Thread Nikolaus Rath
Hi, I'm trying to be very clever: class tst(object): def destroy(self): print 'Cleaning up.' self.__del__ = lambda: None def __del__(self): raise RuntimeError('Instance destroyed without running destroy! Hell may break loose!') However, it doesn't work:

Re: Dynamically change __del__

2010-04-30 Thread Jerry Hill
On Fri, Apr 30, 2010 at 3:16 PM, Nikolaus Rath nikol...@rath.org wrote: Apparently Python calls the class attribute __del__ rather than the instance's __del__ attribute. Is that a bug or a feature? Is there any way to implement the desired functionality without introducing an additional

Re: Dynamically change __del__

2010-04-30 Thread Lie Ryan
On 05/01/10 05:16, Nikolaus Rath wrote: Hi, I'm trying to be very clever: snip Apparently Python calls the class attribute __del__ rather than the instance's __del__ attribute. Is that a bug or a feature? Is there any way to implement the desired functionality without introducing an

Re: Dynamically change __del__

2010-04-30 Thread Peter Otten
Nikolaus Rath wrote: Apparently Python calls the class attribute __del__ rather than the instance's __del__ attribute. Is that a bug or a feature? Is there any way to implement the desired functionality without introducing an additional destroy_has_been_called attribute? For newstyle classes

Re: Dynamically change __del__

2010-04-30 Thread Lie Ryan
On 05/01/10 05:39, Lie Ryan wrote: On 05/01/10 05:16, Nikolaus Rath wrote: Hi, I'm trying to be very clever: snip Apparently Python calls the class attribute __del__ rather than the instance's __del__ attribute. Is that a bug or a feature? Is there any way to implement the desired