class Singleton(object):
# 定义静态变量实例
__instance = None
def __init__(self):
pass
def __new__(cls, *args, **kwargs):
if not cls.__instance:cls.__instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls.__instance
# 定义静态变量实例
__instance = None
def __init__(self):
pass
def __new__(cls, *args, **kwargs):
if not cls.__instance:cls.__instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls.__instance
__new__会在__init__之前形成,super不是函数,而是一个类,详细去看本博客的super()函数的链接。
cls常常表示类。instance(obi,cls),检查obj是够为cls的实例。cls:class