class Singleton(type):
def __call__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super().__call__(*args, **kwargs)
print(cls.instance)
return cls.instance
class Capital(metaclass=Singleton):
instance=None
def init(self, cityname):
self.cityname = city_name
def name(self):
return self.city_name
In the CapitalCity answers I saw codes like above.
I have difficulty in understanding what is happening in the 4th line.
"cls.instance=super().call(args,*kwargs)".
I've searched and understood super() here refers to class 'type'.
I thought this line is bizarre, because although call method requires information about the type of instance to be instantiated, there seems to be no information about that.
I would appreciate it if someone could explain about this.
Created at: 2021/08/17 04:17; Updated at: 2021/08/19 06:42
The question is resolved.