一些我看到的人做所有的时间是:重写父类的方法
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
super(ExcitingMan, self).say_hi() # Calling the parent version once done with custom stuff.
的东西,我从来没有看到有人做的是:
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
return super(ExcitingMan, self).say_hi() # Returning the value of the call, so as to fulfill the parent class's contract.
这是因为我与所有挂错的程序员,还是有一个很好的理由?
对于大多数处理器来说,ExcitingMan.say_hi()的返回值通常太令人兴奋了。 – intuited 2010-09-27 07:40:35