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

前端 未结 8 1810
隐瞒了意图╮
隐瞒了意图╮ 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:12

    f is an (instance) method. However, you are calling it via fibo.f, where fibo is the class object. Hence, f is unbound (not bound to any class instance).

    If you did

    a = fibo()
    a.f()
    

    then that f is bound (to the instance a).

提交回复
热议问题