摘要:
1.Python如何实现单例模式?参考答案:Python有两种方式可以实现单例模式,下面两个例子使用了不同的方式实现单例模式:1. 1 class Singleton(type): 2 def __init__(cls, name, bases, dict): 3 super(Singleton, cls).__init__(name, bases, dict) 4 cls.instance = None 5 def __call__(cls, *args, **kw): 6 if cls.instance is None: 7 cls.instance = super(Singleton, 阅读全文
posted @ 2011-07-22 15:30 仆本浪人 阅读(839) 评论(0) 推荐(0) 编辑