码迷,mamicode.com
首页 > 编程语言 > 详细

Python 单例模式

时间:2017-07-24 23:40:07      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:single   att   *args   instance   单例模式   log   rgs   obj   logs   

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

 

Python 单例模式

标签:single   att   *args   instance   单例模式   log   rgs   obj   logs   

原文地址:http://www.cnblogs.com/m2492565210/p/7231557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!