Skynet

---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

代码
参考:http://www.python.org/dev/peps/pep-0318/
def singleton(cls):
    instances 
= {}
    
def getinstance():
        
if cls not in instances:
        
print "new"
            instances[cls] 
= cls()
        
return instances[cls]
    
return getinstance

@singleton
class MyClass:
    
pass


x1
=MyClass()
#print new
x2=MyClass()




整理 www.blogjava.net/Good-Game
posted on 2009-04-16 23:20 刘凯毅 阅读(1031) 评论(0)  编辑  收藏 所属分类: python

只有注册用户登录后才能发表评论。


网站导航: