# mysingleton.py
class My_Singleton(object):
def foo(self):
pass
my_singleton = My_Singleton()
from mysingleton import my_singleton
my_singleton.foo()
class Singleton(object):
_instance = None
def __new__(cls, *args, **kw):
if not cls._instance:
cls._instance = super(Singleton,cls).__new__(cls,*args,**kw)
return cls._instance
class MyClass(Singleton):
a = 1
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |