考虑以下情况:
class test:
def foo(self, o):
print(o)
@staticmethod
def bar(o):
print(o)
@classmethod
def qux(cls, o):
print(cls)
print(o)
def baz(o):
print(o)
t = test()
class A:
meth1 = t.bar
meth2 = t.foo
meth3 = baz
meth4 = t.qux
a = A()
a.meth1()
a.meth3()
# a.meth4()
# a.meth2()
这工作得很好,但是如果我打电话,meth2/4
我会收到以下错误:
TypeError: <foo/qux>() missing 1 required positional argument: 'o'
有什么办法可以让我像t.foo
and一样工作吗?t.qux
t.bar
baz