Hello, I'm trying to execute this simple code:
class Person:
population = 0
def __init__(self, name):
print 'Creating % s peron' % name
self.name = name
Person.population += 1
def __del__(self):
print 'Destroying %s person' % self.name
Person.population -= 1
prvi = Person('Asimi')
drugi = Person('Mici')
I'm using Wing IDE trial and here's what is output in debug mode:
Creating Asimi peron
Creating Mici peron
Destroying Mici person
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in <bound method Person.__del__ of <__main__.Person instance at 0x00B29558>> ignored
Destroying Asimi person
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in <bound method Person.__del__ of <__main__.Person instance at 0x00B29530>> ignored
Problem is solved by putting self.population - = 1 in __del__ method, but the example is from book ByteOfPython and population is supposed to be class variable...
I really don't have a clue what is wrong here...