单例模式

2020-05-29  本文已影响0人  你的学生_张老师
class Singleton:
    def __new__(cls, *args, **kwargs):
        if not hasattr( cls, '_instance'):
            _instance = super().__new__(cls, *args, **kwargs)
            cls._instance = _instance
        return cls._instance

class Test(Singleton):
    pass
上一篇下一篇

猜你喜欢

热点阅读