您可以通过实现
__call__方法来使对象可调用:
class FunctionLike(object): def __call__(self, a): print("I got called with {!r}!".format(a))fn = FunctionLike()fn(10)# --> I got called with 10!
您可以通过实现
__call__方法来使对象可调用:
class FunctionLike(object): def __call__(self, a): print("I got called with {!r}!".format(a))fn = FunctionLike()fn(10)# --> I got called with 10!