__new__ 与 __init__的区别

原文地址:http://www.cnblogs.com/ifantastic/p/3175735.html

 

单例模式

class Singleton(object):
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):
            cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
        return cls._instance

 

posted @ 2018-03-08 19:55  骑者赶路  阅读(92)  评论(0编辑  收藏  举报