1:Python如何实现单例模式? Python有两种方式可以实现单例模式,下面两个例子使用了不同的方式实现单例模式:1.class Singleton(type):def _init_(cls, name, bases, dict):super(Singleton, cls)._init_(name, bases, dict)cls.instance = Nonedef _call_(cls, *args, *kw):if cls.instance is None:cls.instance = super(Singleton, cls)._call_(*args, *kw)return cls.instanceclass MyClass(object):_metaclass_ = Singletonprint MyClass()print MyClass()2. 使用decorator来实现单例模式def singleton(cls):instances = def getinstance():if cls