class Singleton(object):注:__new__方法用于生成类实例,__new__应返回一个类实例,返回值会传到__init__方法用于生成实例,对应着__init__方法中的"self"参数。 标签:__,python,模式,instance,init,实例,单例,new,cls From: https://www.cnblogs.com/CJTARRR/p/17591111.html
def __new__(cls, *args, **kwargs):
if not hasattr(cls, '_instance'):
cls._instance = super(Singleton, cls).__new__(cls)
return cls._instance