【发布时间】:2017-10-17 17:25:04
【问题描述】:
class Foo(object):
def whee(self):
return 77
class Bar(Foo):
def whee(self):
return super(Bar, self).whee() + 1
class Baz(Foo):
def whee(self):
return super(self.__class__, self).whee() + 1
Bar 和 Baz 都为 whee() 返回相同的结果。我习惯了Bar 中的语法。我有什么理由不应该使用Baz 中的语法?
【问题讨论】:
-
永远不要将
self.__class__传递给super。如果就这么简单,super一开始就不会要求这个论点。
标签: python python-2.7 class-hierarchy