I'm trying to create basic abstract class with mechanism for saving of set of all created instances.
class Basic(object):
__metaclass__ = ABCMeta
allInstances = set()
def __init__(self, name):
self.allInstances.add(self)
def __del__(self):
self.allInstances.remove(self)
The problem is that set allInstances
saves instances of all child classes. Should I add this lines for every child class separately or there is way to create sets for every child class in basic class?