2014年3月20日

python singleton

摘要: 使用decorator的方式: 1 def singleton(cls): 2 instance = {} 3 def returnInstance(): 4 if cls not in instance: 5 instance[cls] = cls() 6 return instance[cls] 7 return returnInstance 8 9 @singleton10 class MyClass(object):11 def __init__(self):12 self.x =... 阅读全文

posted @ 2014-03-20 21:28 saobchj 阅读(225) 评论(0) 推荐(0) 编辑

导航