我在 Python 3.11 版本中面临“RuntimeError: super(): no argument”。我使用 PyCharm 作为编码控制台。谁能帮我解决以下代码:
class Parent:
def __init__(self):
print("This is a parenet class constructor.")
def method_p1(self):
print("This is an parent instance method.")
@classmethod
def method_p2_class(cls):
print("This is a parent class method.")
@staticmethod
def method_p2_static():
print("This is a parent static method.")
class Child(Parent):
def __init__(self):
super().__init__()
print("This is a child class constructor.")
def method_c1(self):
print("This is a child class instance method.")
super().method_p1()
child_obj = Child()
child_obj.method_p1()
Error Output : super().method_p1()
^^^^^^^
RuntimeError: super(): no arguments
如果你想要method_c1函数中的super()方法,实现这个:
def method_c1(self):
print("This is a child class instance method.")
super().method_p1()