代码
参考: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