Re: super not working in __del__ ?

2005-02-17 Thread Christopher J. Bottaro
Jeff Shannon wrote: Python's __del__() is not a C++/Java destructor. Learn something new everyday... What is it then? Excuse my ignorance, but what are you suppose to do if your object needs to clean up when its no longer used (like close open file handles, etc)? Are you use supposed to make

Re: super not working in __del__ ?

2005-02-17 Thread Jeff Shannon
Christopher J. Bottaro wrote: Jeff Shannon wrote: Python's __del__() is not a C++/Java destructor. Learn something new everyday... What is it then? Excuse my ignorance, but what are you suppose to do if your object needs to clean up when its no longer used (like close open file handles, etc)?

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Fredrik Lundh wrote: in this case, def __del__(self): super(self.__class__, self).__del__() should do the trick. Only if nobody ever tries to subclass your class, and if they aren't going to subclass it why bother to use super in the first place. class Base(object): def

Re: super not working in __del__ ?

2005-02-16 Thread Ola Natvig
Duncan Booth wrote: Fredrik Lundh wrote: in this case, def __del__(self): super(self.__class__, self).__del__() should do the trick. Only if nobody ever tries to subclass your class, and if they aren't going to subclass it why bother to use super in the first place. class Base(object):

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Ola Natvig wrote: def __del__(self): There should be a super(self.__class__, self)._del__() here if I'm not totaly wong, which could be the case here ;) print Base.__del__ There was one, but for some reason you trimmed it out of your quote: The original

Re: super not working in __del__ ?

2005-02-16 Thread Brian Beck
Duncan Booth wrote: There was one, but for some reason you trimmed it out of your quote: The original code before you trimmed it was: Look carefully, he was commenting on the contents of class Base (which does omit the line he suggests), not class B. Whether he's correct or not, I'm not wizardly

Re: super not working in __del__ ?

2005-02-16 Thread Duncan Booth
Ola Natvig wrote: Duncan Booth wrote: class Base(object): def __del__(self): There should be a super(self.__class__, self)._del__() here if I'm not totaly wong, which could be the case here ;) print Base.__del__ Thanks to Brian Beck for pointing out I

Re: super not working in __del__ ?

2005-02-16 Thread Christopher J. Bottaro
Fredrik Lundh wrote: Warning: Due to the precarious circumstances under which __del__() methods are invoked, exceptions that occur during their execution are ignored, and a warning is printed to sys.stderr instead. Also, when __del__() is invoked in response to a module being

Re: super not working in __del__ ?

2005-02-16 Thread Fredrik Lundh
Christopher J. Bottaro wrote: 2 Questions... 1) Why does this never happen in C++? Or does it, its just never happened to me? C++ uses an entirely different allocation model. if you think in C++ when you write Python, you will write bad Python. 2) I can understand random destruction of

Re: super not working in __del__ ?

2005-02-16 Thread Jeff Shannon
Christopher J. Bottaro wrote: 2 Questions... 1) Why does this never happen in C++? Or does it, its just never happened to me? 2) I can understand random destruction of instantiated objects, but I find it weird that class definitions (sorry, bad terminology) are destroyed at the same time. So

Re: super not working in __del__ ?

2005-02-16 Thread Christopher J. Bottaro
Jeff Shannon wrote: Christopher J. Bottaro wrote: 2 Questions... 1) Why does this never happen in C++? Or does it, its just never happened to me? 2) I can understand random destruction of instantiated objects, but I find it weird that class definitions (sorry, bad terminology) are

Re: super not working in __del__ ?

2005-02-16 Thread Jeff Shannon
Christopher J. Bottaro wrote: So encapsulating your script in a main function fixes the problem: Not necessarily. because all the objects instantiated in main() will be deleted when main ends, but before the interpreter shuts down, thus the objects will have access to all the symbols in module's

super not working in __del__ ?

2005-02-15 Thread Christopher J. Bottaro
I get this exception when I run the following code: Exception exceptions.TypeError: 'super() argument 1 must be type, not None' in bound method Txrposdn.__del__ of __main__.Txrposdn object at 0xf6f7118c ignored Here is the code: class Txrposdn(PRI.BasicBatch): def __init__(self, *argv):

Re: super not working in __del__ ?

2005-02-15 Thread Jeff Epler
When a Python program exits, various steps of cleanup occur. One of them is that each entry in the __dict__ of each module is set to 'None'. Imagine that your __del__ runs after this step of the cleanup. The reference to the module-level variable that names your class is no longer available I

Re: super not working in __del__ ?

2005-02-15 Thread Fredrik Lundh
Christopher J. Bottaro wrote: I get this exception when I run the following code: Exception exceptions.TypeError: 'super() argument 1 must be type, not None' in bound method Txrposdn.__del__ of __main__.Txrposdn object at 0xf6f7118c ignored reading the documentation never hurts: