The program I ran is
class Account(object):
counter = 0
def __init__(self, holder, number, balance, credit_line = 1500):
Account.counter += 1
def __del__(self):
Account.counter -= 1
print "Counter\t", Account.counter
a1 = Account("Homer Simpson", 2893002, 2325.21)
print "Counter\t", Account.counter
a2 = Account("Fred Flintstone", 2894117, 755.32)
print "Counter\t", Account.counter
a3 = a2
print "Counter\t", Account.counter
a4 = Account("Bill Gates", 2895007, 5324.32)
print "Counter\t", Account.counter
del a4
print "Counter\t", Account.counter
The first time I run it the output is correct:
Counter 0
Counter 1
Counter 2
Counter 2
Counter 3
Counter 2
But if I run it again in the same console:
Counter 0
Counter 0
Counter 1
Counter 0
Counter 1
Counter 0
Any idea why the output changes the second time around?