在此处找不到答案,因此将其发布。 出现此错误:
main() takes 1 positional argument but 2 were given
对于此代码,B
尝试扩展A
的方法,而该方法将实习生调用其他类方法。
class A:
@classmethod
def run(cls):
cls.main(cls)
@classmethod
def main(cls):
"""Override and set main logic here
"""
pass
class B(A):
title = "Hello"
@classmethod
def run(cls, name):
cls.name = name
super().run()
@classmethod
def main(cls, *args):
"""Override and set main logic here
"""
print(cls.title, cls.name)
B.run('Bob') # Hello Bob
答案 0 :(得分:0)
super()
通过:
(<class '__main__.B'>, <class '__main__.B'>)
当B.main()
调用时,进入A.run()
:
只需收集任何其他位置参数即可使B
处理额外的参数:
def main(cls, *args):