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

Python 单例

时间:2015-02-28 10:05:31      阅读:128      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!