在Python中,我實現了Inheritance。
TypeError:無法綁定的方法fun1()必須用c1實例作爲第一個參數調用(取而代之)
class c1(object):
def __init__(self):
pass
def fun1(self):
print 'In Fun1'
class c2(c1):
def __init__(self):
c1.__init__(self)
def fun2(self):
c1.fun1()
print 'In Fun2'
obj = c2()
obj.fun2()
當我運行它,我收到以下錯誤:
Traceback (most recent call last):
File "C:/Users/madhuras/Documents/inheritance_example.py", line 15, in <module>
obj.fun2()
File "C:/Users/madhuras/Documents/inheritance_example.py", line 11, in fun2
c1.fun1()
TypeError: unbound method fun1() must be called with c1 instance as first argument (got nothing instead)
爲什麼會出現這個錯誤的代碼下面給出? 在此先感謝!
您需要將自己傳遞給'c1.fun1()' –