您可以通过实现
__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!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)