我舉個例子。我有兩個班。 A
是B
的超類。調用超類超類的方法
class A(object):
def p(self):
print "a"
class B(A):
def p(self):
print "b"
super(A, self).p()
現在我有一個新類C
。類C
是子類的B
,應再次改寫方法p
,這樣的:
class C(B):
def p(self):
print "c"
# here call the method p of the 'supersuper'class A
# without calling the method p of the superclass B
...
我如何可以覆蓋該方法的類C
的超B
的p()
和調用的方法p()
超級超類A
未調用超類的方法p
B
?有人有想法嗎?
P/S:方法名稱必須相同。
嗯,它是Python,我們都在這裏同意大人,所以它可以讓你做類似'Ap(self)'的事情或者通過'self .__ mro__'手動行走,但是你的需求會破壞一些基本的繼承規則,它不會被很好地支持。 –
是的,我知道,這不是很好。但我需要繼承一個類來改變他的方法而不需要編輯。 – qvpham