首页 > 编程语言 > 详细

Python 单例

时间:2015-02-28 10:04:56      阅读:201      评论:0      收藏:0      [点我收藏+]
 1 class Singleton(object):
 2     def __new__(cls, *args, **kwargs):
 3         if _inst not in vars(cls):
 4             cls._inst = super(Singleton, cls).__new__(cls, *args, **kwargs)
 5         return cls._inst
 6 
 7     def __init__(self):
 8         print "init"
 9 
10 
11 class SingleSpam(Singleton):
12     def __init__(self, s):
13         self.s = s
14         print "creat"

 

Python 单例

原文:http://www.cnblogs.com/zj1111184556/p/4304688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!