Beginner's Question (or bug in python?)

Kalle Svensson kalle at gnupung.net
Fri Apr 20 13:32:43 EDT 2001


Sez Rolf Magnus:
> Hello. I have a problem understanding why the behaviour of python depends 
> on class names. I have the following python script:
[snip]
> 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.

Quoting the Reference Manual:
"""
Also, when __del__() is invoked is response to a module being deleted (e.g.,
when execution of the program is done), other globals referenced by the
__del__() method may already have been deleted. 
"""
See http://www.python.org/doc/current/ref/customization.html for more.

Peace,
  Kalle
-- 
Email: kalle at gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]




More information about the Python-list mailing list