python 单例

 

class Dog(object):
    __first_new = True
    __instance = None
        def __new__(cls):
                if cls.__first_new:
                        cls.__instance = object.__new__(cls)
                        cls.__first_new = False
                        return cls.__instance
                 else:
                        return cls.__instance
a = Dog()
b = Dog()

 

posted @ 2018-12-05 12:33  anobscureretreat  阅读(154)  评论(0)    收藏  举报