我可以帮助您翻译以下内容,涉及IT技术方面的问题。
我想要在Python中继承一个方法的“子方法”。请问有谁能帮助我弄清楚如何实现这个功能吗?
以下是我想做的一个示例:
class A(object):
def method(self, val):
def submethod():
return "Submethod action"
if not val:
return submethod()
return "Method action"
a = A()
class B(A):
def method(self, val):
#inherit submethod ?
def submethod():
return "Another submethod action"
return super(B,self).method(val)
b = B()
print "A : "
print a.method(True)
>> Method action
print a.method(False)
>> Submethod action
print "B : "
print b.method(True)
>> Method Action
print b.method(False)
Actual answer :
>> Submethod Action
**Wanted answer :
>> Another submethod action**
敬礼,
昆汀