I am trying to understand the relation in between python metaclass and class. I was trying to create singleton class and found this code
class SingleTon(type):
def __call__(self, *args, **kwargs):
if self._instances is None:
self._instances = super(SingleTon, self).__call__(*args, **kwargs)
return self._instances
class Counter:
__metaclass__ = SingleTon
_instances = None
def __init__(self):
self.count = 1
c = Counter()
my question here is how counter class object is getting created using metaclass. I know metaclass call method gets called whenever we create an object but the confusion is here what this code super(SingleTon, self).__call__(*args, **kwargs) does here. Please explain. It would be very appreciable.