__call__
__call__
__call__
方法的执行是由对象后加括号触发的,即:对象() 或者 类()()class Foo:
def __init__(self):
print('__init__触发了')
def __call__(self, *args, **kwargs):
print('__call__触发了')
obj = Foo() # 执行 __init__
__init__触发了
obj() # 执行 __call__
__call__
原文:https://www.cnblogs.com/Dr-wei/p/11851385.html