unbound method must be called with instance as first argument (got nothing instead)

19,053
  1. You do not instantiate anything

  2. All methods must take at least one parameter, traditionally called self.

  3. You need self to access object fields. Your code right now modifies local variables which do not exist in that scope.

Share:
19,053
Toalp
Author by

Toalp

Updated on June 05, 2022

Comments

  • Toalp
    Toalp almost 2 years

    Im trying to move all classes from one Inheritance. I wrote this tiny script:

    class c1:
        def move():
            x+=1
            y+=1
    class c2(c1):
        y=1
        x=2
    c=c2
    c.move()
    print(str(c.x)+" , "+str(c.y))
    

    when i run it i get:

    Traceback (most recent call last):   File "/home/tor/Workspace/try.py", line 9, in <module>
         c.move() TypeError: unbound method move() must be called with c2 instance as first argument (got nothing instead) [Finished in 0.1s
    with exit code 1]
    

    what did I do wrong?