装饰器实现
def singleton(cls): _instance = {} def inner(): if cls not in _instance: _instance[cls] = cls() return _instance[cls] return inner @singleton class Cls(object): def __init__(self): pass cls1 = Cls() cls2 = Cls() print(id(cls1) == id(cls2))View Code
标签:__,cls1,instance,单例,cls,def,Cls From: https://www.cnblogs.com/tslam/p/18139818