I am having a Python problem. I have two classes, both inheriting the class 'Animal'. I want a counter, that means Animal.count_of() should return the number of objects.
Please have a look at this code:
number = 0
Animal.number += 1
Animal.number -= 1
l1 = Laus()
l2 = Laus()
l3 = Laus()
l4 = Laus()
b1 = Bug()
This is not working because both classes are using the same class variable (number) which means the number in the last line is 5, not 1. I could obviously have one class variable for Bug and one for Laus, but that would mean I'd have to have two .count_of()-methods as well (and more would have to be duplicated, I only pasted a stripped down code).
Is there a trick to have one base-class Animal with a counter or do I really have to do everything twice?