unbound method f() must be called with fibo_ instance as first argument (got classobj instance instead)

前端 未结 8 1794
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 23:42

In Python, I\'m trying to run a method in a class and I get an error:

Traceback (most recent call last):
  File \"C:\\Users\\domenico\\Desktop\\py\\main.py\"         


        
8条回答
  •  臣服心动
    2020-11-29 00:11

    In Python 2 (3 has different syntax):

    What if you can't instantiate your Parent class before you need to call one of its methods?

    Use super(ChildClass, self).method() to access parent methods.

    class ParentClass(object):
        def method_to_call(self, arg_1):
            print arg_1
    
    class ChildClass(ParentClass):
        def do_thing(self):
            super(ChildClass, self).method_to_call('my arg')
    

提交回复
热议问题