Python 3.11 中的 SUPER() 方法 - “运行时错误:super():无参数”

问题描述 投票:0回答:1

我在 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
python python-3.x oop pycharm superclass
1个回答
0
投票

如果你想要method_c1函数中的super()方法,实现这个:

    def method_c1(self):

        print("This is a child class instance method.")
        super().method_p1() 
© www.soinside.com 2019 - 2024. All rights reserved.