python 单例模式

class Single:

    __v = None

    @classmethod
    def get_instance(cls):
        if cls.__v:
            return cls.__v
        else:
            cls.__v = Single()
            return cls.__v


obj1 = Single.get_instance()
print(obj1)

obj2 = Single.get_instance()
print(obj2)

 

posted @ 2017-10-11 20:58  kennyhip  阅读(127)  评论(0)    收藏  举报