Dlaczego ten destruktor nie dziala [_LONG_]

Jacol jgrzebyta at NO.gazeta.pl.SPAM
Tue Feb 6 16:19:37 EST 2007


Sulsa wrote:

> Mam klase A po ktorej dziedziczy B i jesli w destruktorze klasy B
> wywolam:
> self.__class__.__bases__[0].__del__(self)
> 
> to wszytkos jest ok, i destruktor klasy a jest wywolywany, jesli
> natomiast napisze: A.__del__(self)  to otrzymuje nastepujacy wyjatek:
> Exception exceptions.AttributeError: "'NoneType' object has no
> attribute '__del__'" in <bound method B.__del__ of <__main__.B instance
> at 0x2b025d04a830>> ignored
> 
> czemu tak sie dzieje?

??

Cześć,
Właściewie to nie rozumiem sensu pytania. :)

Ja zrobiłem tak:

class A:
        def __del__(self):
                print "Delete A"

class B(A):
        def __del__(self):
                A.__del__(self)
                print "Delete B"

potem sworzyłem instancję: InstanceB=B()

potem uruchomiłem destruktory: del(InstanceB) i moim oczom ukazał się
komunikat:

Delete A
Delete B

1) Czy atrybut A.__del__(self) zosatł zdefiniowany przez Ciebie?? Domyślny
nie jest brany pod uwagę. Sprawdziłem.

class A:
        pass
class B(A):
        def __del__(self):
                A.__del__(self)
                print "Cośtam"

potem 

insta=B()
del(insta) daje Exception exceptions.AttributeError: "class A has no
attribute '__del__'" in <bound method B.__del__ of <__main__.B instance at
0xb7cf20cc>> ignored

PS.: Python 2.4.4c1



More information about the Python-list mailing list