I need to overwrite a method in a Python class, however this method needs to keep his behaviour in certain condition. An example of what I need:
class DefaultClass(object):
def __init__(self):
self.number = 5
def do_something(self, x):
self.number = self.number * x
return self.number
class ChildClass(DefaultClass):
def __init__(self):
self.flag = False
def do_something(self, x):
if self.flag is False:
# do_something method should works as defined in DefaultClass
else:
self.number = self.number + x
return self.number
An important point here, I dont have access to the implementation of the method that I want to overwrite (life is not so simple).
Thanks in advance!