首页 > 代码库 > Python 单例模式

Python 单例模式

class Singleton(object):
    def __new__(cls, *args, **kw):
        if not hasattr(cls, _instance):
            orig = super(Singleton, cls)
            cls._instance = orig.__new__(cls, *args, **kw)
        return cls._instance

 

Python 单例模式