Beginner's Question (or bug in python?)
Rolf Magnus
ramagnus at zvw.de
Fri Apr 20 10:47:52 EDT 2001
Hello. I have a problem understanding why the behaviour of python depends
on class names. I have the following python script:
#!/usr/bin/python
class Fred:
def __init__(self):
print('initializing fred')
def __del__(self):
print('deleting fred')
def test(self):
print('Hello world')
class Foo(Fred):
def __init__(self):
Fred.__init__(self)
print ('initializing foo')
def __del__(self):
print('deleting foo');
Fred.__del__(self)
x = Foo()
x.test()
If I execute this, I get the following:
initializing fred
initializing foo
Hello world
deleting foo
Exception exceptions.AttributeError: "'None' object has no attribute
'__del__'" in <method Foo.__del__ of Foo instance at 80c3c00> ignored
If I instead call the base class Hans instead of Fred, it works as expected:
initializing fred
initializing foo
Hello world
deleting foo
deleting fred
This seems to be the case for Python 1.52 and 2.1 (not sure about 2.1,
because I only tested the first case and got the error message).
And if I add a "del x" after the last line, it works in both cases. This
seems odd to me, but since I am a python beginner, there is perhaps
something important I don't know.
More information about the Python-list
mailing list