I’m trying to achieve the following:
class Data(object):
def __init__(self, data):
self.data = data
self.valid = False
#Analyze and validate data
self.preprocess_data()
self.validate_data()
def preprocess_data():
pass
def validate_data():
#process data
class MyData(Data):
def __init__():
super(MyData,self).__init__(data)
def preprocess_data(self):
#preprocess it
When a subclass executes the overriden preprocess_data method, I want to automatically perform the following operation: self.data = self.data.copy()
How can this be done (if at all)? I thought about decorating preprocess but I don’t think that overridden methods that are decorated in the base class inherit the “decoration”
This tests if the function behind
self.preprocess_dataisData.preprocess_data; if not it copies your data. Of course this requires you to call_preprocess_datain your class so the additional code is actually executed.