Stupid q: Where is the destructor?

Kjell Kolsaker kjell.kolsaker at kkt.ntnu.no
Thu Aug 24 11:13:55 EDT 2000


Another question: Static methods?

# Simple sample...

>>> class foo:
...  i=12
...  def getI():
...    return foo.i
...
>>> print foo.getI()
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: unbound method must be called with class instance 1st argument
>>>

I have tried to define a static method, where it has no sense to pass
a self parameter. My try doesn't work. Why?
And what is the medicine? It will work if I redefine "getI()" to "getI(self)"
and then:

>>> dummy = foo()
>>> print foo.getI(dummy)
12

But I am sure PYTHON has a better semantic for this hidden in
somewhere in it's language reference ;-?

Gerrit Holl wrote:

> On Wed, 23 Aug 2000 16:05:52 +0200, Kjell Kolsaker wrote:
> > Hi,
> >
> > I am new to Python, so excuse me if I ask for an obvious thing,
> > Didn't find anything in the tutorial, nor in the faq.
> >
> > I want to define a class with some side effect in the
> > constructor that I need to clean up whenever an object is deleted.
> > Default destruction doesn't help me. In the documentation,
> > I find __init__, but no "__finalize__" or whatever it should be called.
> >
> > Do anybody know the answer? Have I missed something obvious?
>
> You have indeed. You are looking for __del__.
> For your information, it can be found at the following place in the
> docs:
>
> Language Reference -> Data model -> Special method names -> Basic customization
>
> URL: http://www.python.org/doc/current/ref/customization.html
>
> And the name is............ __del__!
>
> regards,
> Gerrit.
>
> --
> 1010111 1101001 1100101 0100000 1100100 1101001 1110100
> 0100000 1101100 1100101 1100101 1110011 1110100 0100000
> 1101001 1110011 0100000 1100111 1100101 1101011 0100001




More information about the Python-list mailing list