I have 2 classes:
class ClassOne:
def __init__(self, file_name):
self.file_name = file_name
self.dict = {}
def load(self):
#reads from file and parse into dictionary self.dict
def regions(self):
return list(self.dict.keys()) #returns a list of keys of the dictionary dict
and
class ClassTwo:
def __init__(self, file_name):
self.file_name = file_name
self.dict = {}
def load(self):
regions = ClassOne.regions(self)#The issue is here
The load() method does similar things in both classes: open file csv, read from file and parse data into dictionary dict. The only difference that method load() of ClassTwo must call method regions() of the class ClassOne Also, I have main function where I create objects :
def main():
class_one_object = ClassOne("file1.csv")
class_one_object.load ():
class_two_object = ClassTwo("file2.csv")
class_two_object.load ():
if __name__ == "__main__":
main()
The problem is that I get empty list here: regions = ClassOne.regions(self) because I call ClassOne.regions() with self of ClassTwo, but I need to pass self of ClassOne there somehow.
Also, if I create class_one_object, class_two_object without main, everything works, but I need to use main. Could you help me with the issue, please? I would appreciate any help. Thanks.