I have a Python module consisting of multiple classes, of which the first one does an extensive data import and the following ones create files based on the output of the first class:
class ImportData:
def __init__(self):
self.result_csv = None
def import_file(self):
self.result_csv = pd.read_csv(file.csv)
return self.result_csv
class CreateDataObject1:
def __init__(self):
import_data = ImportData()
self.data_object_1 = import_data.result_csv
def create(self):
self.data_object_1 = self.data_object_1.loc[self.data_object_1["Zulu"]]
class CreateDataObject2:
def __init__(self):
import_data = ImportData()
self.data_object_2 = import_data.result_csv
def create(self):
self.data_object_2 = self.data_object_2.loc[self.data_object_2["Foxtrott"]]
As you can see, I want to pass the instance variable from the first class to all other classes so that they can use it further. However, I do not want to invoke the import method in the first class every time, because it is quite computationally expensive. How can I ensure that all following classes only take the resulting instance variables from the first class without invoking its methods? Would it be recommendable to work with staticmethod / classmethod / class inheritance here? Thanks!