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?
You do not instantiate anything
All methods must take at least one parameter, traditionally called
self
.You need
self
to access object fields. Your code right now modifies local variables which do not exist in that scope.