我有一個非常簡單的情況:調用父類的方法
我有這個類:
class animal(object):
def do_stuff(self):
return self.__yell()
class dog(animal):
def yell(self):
print("yelling")
我希望能夠調用
d = dog()
d.do_stuff()
但是我得到
AttributeError: 'dog' object has no attribute '_animal__yell'
父類將impl ement do_stuff會調用每個子類的叫喊方法,但這不起作用
看到https://docs.python.org/2/library/functions.html#super –
你爲什麼前綴'yell'爲'__yell'? – Kupiakos
[tag:python2]或[tag:python3] ... –