例如,我有下一个代码:
class Dog:
def bark(self):
print "WOOF"
class BobyDog( Dog ):
def bark( self ):
print "WoOoOoF!!"
otherDog= Dog()
otherDog.bark() # WOOF
boby = BobyDog()
boby.bark() # WoOoOoF!!
BobyDog 是 Dog 的子代,并且已经覆盖了 instancemethod "bark"。
如何从类“BobyDog”的实例中引用父方法“bark”?
换句话说:
class BobyDog( Dog ):
def bark( self ):
super.bark() # doesn't work
print "WoOoOoF!!"
otherDog= Dog()
otherDog.bark() # WOOF
boby = BobyDog()
boby.bark()
# WOOF
# WoOoOoF!!