我想在classmethod中使用服务函数,其中服务函数在其他地方定义.我希望是动态的,所以我可以在不同的情况下定义不同的功能.我试过这个:
def print_a():
print 'a'
class A:
func = print_a
@classmethod
def apply(cls):
cls.func()
A.apply()
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
unbound method print_a() must be called with A instance as first argument (got nothing instead)
任何想法如何使其工作?