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()

原文地址:https://www.cnblogs.com/sea-stream/p/10070243.html