我想创建一个向另一个方法(set_result)注入参数的方法(set)。我已经尝试过使用partial,如下所示。
from functools import partial
class MyClass(MyClassParent):
set = partial(MyClassParent.set_result, None)但这不管用。在MyClass实例上调用set时,我收到以下错误:
TypeError: set_result() takes exactly 2 arguments (1 given)我假设这意味着没有传递隐式self。如果我像这样写set,它就能工作:
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
self.set = partial(self.set_result, None)如何使用前一种方法包装set_result?
发布于 2012-03-24 20:51:45
set = staticmethod(partial(MyClassParent.set_result, None))https://stackoverflow.com/questions/9851890
复制相似问题