I would like inherit a 'submethod' of a method in python. Could somebody help me to figure out how to do this please ?
Example of what I want to do :
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**
Kind regards,
Quentin
You can't "inherit" submethod since it's local to method and doesn't even exist until method is run.
Why not simply make it a top-level method of A and B?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With