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

前端 未结 8 1793
隐瞒了意图╮
隐瞒了意图╮ 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-28 23:52

    fibo = f.fibo references the class itself. You probably wanted fibo = f.fibo() (note the parentheses) to make an instance of the class, after which fibo.f() should succeed correctly.

    f.fibo.f() fails because you are essentially calling f(self, a=0) without supplying self; self is "bound" automatically when you have an instance of the class.

提交回复
热议问题