T
tpochep
Hi. I have some strange problem (this is usual for newbies ):
#!/usr/bin/python
#sample.py
class Base1:
def __init__(self):
print "Base1.__init__", self
def __del__(self):
print "Base1.__del__", self
class Base2:
def __init__(self):
print "Base2.__init__", self
def __del__(self):
print "Base2.__del__", self
class Derived(Base1, Base2):
def __init__(self):
print "Derived.__init__:"
Base1.__init__(self)
Base2.__init__(self)
def __del__(self):
print "Derived.__del__:"
Base1.__del__(self)
Base2.__del__(self)
print "begin..."
d = Derived()
b = d
print "end..."
The output of this script:
begin...
Derived.__init__:
Base1.__init__ <__main__.Derived instance at 0x1869adcc>
Base2.__init__ <__main__.Derived instance at 0x1869adcc>
end...
Derived.__del__:
Base1.__del__ <__main__.Derived instance at 0x1869adcc>
Base2.__del__ <__main__.Derived instance at 0x1869adcc>
If I change this program a little:
#!/usr/bin/python
#skipped....
print "begin..."
d = Derived()
b1 = d #Here
print "end..."
The output is:
begin...
Derived.__init__:
Base1.__init__ <__main__.Derived instance at 0x1869adcc>
Base2.__init__ <__main__.Derived instance at 0x1869adcc>
end...
Derived.__del__:
Exception exceptions.AttributeError: "'NoneType' object has no
attribute '__del__'" in <bound method
Derived.__del__ of <__main__.Derived instance at 0x1869adcc>> ignored
I tried different names instead of b1, sometimes programm works,
sometimes I have an exception. So it's clear, that I've done some
stupid mistake, but it's not clear for me, python's newbie, where
#!/usr/bin/python
#sample.py
class Base1:
def __init__(self):
print "Base1.__init__", self
def __del__(self):
print "Base1.__del__", self
class Base2:
def __init__(self):
print "Base2.__init__", self
def __del__(self):
print "Base2.__del__", self
class Derived(Base1, Base2):
def __init__(self):
print "Derived.__init__:"
Base1.__init__(self)
Base2.__init__(self)
def __del__(self):
print "Derived.__del__:"
Base1.__del__(self)
Base2.__del__(self)
print "begin..."
d = Derived()
b = d
print "end..."
The output of this script:
begin...
Derived.__init__:
Base1.__init__ <__main__.Derived instance at 0x1869adcc>
Base2.__init__ <__main__.Derived instance at 0x1869adcc>
end...
Derived.__del__:
Base1.__del__ <__main__.Derived instance at 0x1869adcc>
Base2.__del__ <__main__.Derived instance at 0x1869adcc>
If I change this program a little:
#!/usr/bin/python
#skipped....
print "begin..."
d = Derived()
b1 = d #Here
print "end..."
The output is:
begin...
Derived.__init__:
Base1.__init__ <__main__.Derived instance at 0x1869adcc>
Base2.__init__ <__main__.Derived instance at 0x1869adcc>
end...
Derived.__del__:
Exception exceptions.AttributeError: "'NoneType' object has no
attribute '__del__'" in <bound method
Derived.__del__ of <__main__.Derived instance at 0x1869adcc>> ignored
I tried different names instead of b1, sometimes programm works,
sometimes I have an exception. So it's clear, that I've done some
stupid mistake, but it's not clear for me, python's newbie, where