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

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

    Differences in In python 2 and 3 version:

    If you already have a default method in a class with same name and you re-declare as a same name it will appear as unbound-method call of that class instance when you wanted to instantiated it.

    If you wanted class methods, but you declared them as instance methods instead.

    An instance method is a method that is used when to create an instance of the class.

    An example would be

       def user_group(self):   #This is an instance method
            return "instance method returning group"
    

    Class label method:

       @classmethod
       def user_group(groups):   #This is an class-label method
            return "class method returning group"
    

    In python 2 and 3 version differ the class @classmethod to write in python 3 it automatically get that as a class-label method and don't need to write @classmethod I think this might help you.

提交回复
热议问题