Dlaczego ten destruktor nie dziala

S

Sulsa

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?
 
J

Jacol

Sulsa said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top