这是代码:
def singleton(cls):
# https://wiki.python.org/moin/PythonDecoratorLibrary#The_Sublime_Singleton
instance = cls()
instance.__call__ = lambda: instance
return instance
@singleton
class A(object):
def __init__(self):
self.a = 1
装饰器是从python官方维基上复制的
当我运行以下代码时:
a = A()
会提出:
Traceback (most recent call last):
File "xxx", line ab, in yyy
a = A()
TypeError: 'A' object is not callable
我正在使用python 2.7.13。