1
例如,我有下面的代碼:的Python:調用父instancemethod
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是狗的孩子,已經overrided instancemethod 「汪汪」。
如何從類「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!!