Use the class decorator to implement the python singleton pattern

前端 未结 0 754
梦谈多话
梦谈多话 2021-01-13 16:51
def singleton(cls):
    _instance = {}
    def _singleton(*args, **kwargs):
        if cls not in _instance:
            _instance[cls] = cls(*args, **kwargs)
               


        
相关标签:
回答
  • 消灭零回复
提交回复
热议问题