1. 程式人生 > >Python 單例模式

Python 單例模式

single 模式 ttr attr nbsp clas new bsp sat

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 單例模式