一、知识储备
1、__call__方法
1 class Foo: 2 def __call__(self, *args, **kwargs): 3 print(self) 4 print(args) 5 print(kwargs) 6 7 obj = Foo() 8 obj() 9 10 结果为: 11 12 <__main__.Foo object at 0x000002AFE2B4BDA0> 13 () 14 {}
实例化时传参
1 obj(1, 2, 3, a=1, b=2, c=3) 2 3 结果为: 4 5 <__main__.Foo object at 0x000001A1799CBDA0> 6 (1, 2, 3) 7 {‘a‘: 1, ‘b‘: 2, ‘c‘: 3}