a Python bug in processing __del__ method ??

Baoqiu Cui baoqiu at gmail.com
Mon Jan 31 01:46:51 EST 2005


Today I was playing with a small Python program using Python 2.4
on Cygwin (up-to-date version, on Windows XP), but ran into a
strange error on the following small program (named bug.py):

-------------------------------
#!/usr/bin/python

class Person:
population = 0
def __del__(self):
Person.population -= 1

peter = Person()
-------------------------------

The error returned is this:

$ python bug.py
Exception exceptions.AttributeError: "'NoneType' object has no
attribute 'population'" in <bound method Person.__del__ of
<__main__.Person instance at 0xa0c9fec>> ignored

However, if I rename variable name 'peter' to something like 'peter1'
or 'david', the error is gone.  Looks to me the
error only happens to variable name 'peter'.

Does anyone know what is wrong?  Is this a bug only on Cygwin?
- Baoqiu




More information about the Python-list mailing list