How would you append to the method of an inherited object? Say, for example:
class ABeautifulClass(GoodClass):
def __init__(self, **kw):
# some code that will override inherited code
def aNewMethod(self):
# do something
Now I have inherited code from GoodClass, how would I append code to an inherited method. If I inherited code from GoodClass, how would I append to it, instead of basically removing it and rewriting it. Is this possible in Python?
Try using super
class ABeautifulClass(GoodClass):
def __init__(self, **kw):
# some code that will override inherited code
def aNewMethod(self):
ret_val = super().aNewMethod() #The return value of the inherited method, you can remove it if the method returns None
# do something
Learn more about super here
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