2
我试图从一个继承中移动所有类。 我写了这个小脚本:必须使用实例作为第一个参数调用unbound方法(取而代之)
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))
当我运行它,我得到:
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]
我做了什么错?
您没有实例化任何类。 –
你的意思是做'c = c2()'和'c.move()'吗? –
您需要先了解Classes:http://docs.python.org/2/tutorial/classes.html –