a Python bug in processing __del__ method ??

From: Baoqiu Cui (baoqiu_at_gmail.com)
Date: 01/31/05


Date: 30 Jan 2005 22:46:51 -0800

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



Relevant Pages

  • Re: n-body problem at shootout.alioth.debian.org
    ... Peter> shootout.alioth.debian.org the Python program for the n-body ... Peter> problem is about 50% slower than the Perl program. ...
    (comp.lang.python)
  • Re: why cannot assign to function call
    ... The Python program deals solely with references; ... when you say "the Python program", ... The value of an array is the ...
    (comp.lang.python)
  • Re: Hey, get this! [was: import from database]
    ... I agree that this is 2.3-like behavior, but Python cannot lie ... ... [GCC 3.3.3 (cygwin special)] ... > Traceback: ... print "Trying aifc" ...
    (comp.lang.python)
  • Re: Py 2.5 on Language Shootout
    ... Alioth is a great site for selecting the language in which to implement ... Two of the alioth benchmarks, Partial-sums and Spectral-norm, could be ... program was in Python and there was a need to implement a similar ... Python program would be little less than a C program, ...
    (comp.lang.python)
  • import relative (with a directory)
    ... Recently for fun I've been working on a large Python program. ... to specify when I want the code in this project, ... level package name to avoid collisions from other packages. ...
    (comp.lang.python)