Link for my initial part of this question
I am new to object-oriented programming I need to write a BankDataWriterBase base class in the following program using the class diagram given in below to the code. I cannot understand the complete thing that the class diagram has, anybody here to know & explain to me what they actually saying using the class diagram
After my understanding I have done like this :
I know my approach is wrong but i don't know where the mistake happening
import pandas as pd
class ExcelParser:
def __init__(self):
self.config = []
def extract(self, file_name):
raw_excel=pd.read_excel(file_name,sheet_name=None, na_values= None, keep_default_na=False)
return [x for k, v in raw_excel.items() for x in v[v.columns.intersection(conf)].to_dict(orient='records')]
class BankDataWriterBase:
def __init__(self):
self.input_path = file_name
self.output_path = out_path
self.bank_identifier = bank_id
def write_file(self, file_name):
res = True
return res
if __name__ == "__main__":
conf = list(input("ENTER THE LIST HERE : ").split(','))
file_name = input("Enter the full input path here : ")
out_path = input("Enter the full path for the output : ")
bank_id = input("Enter the Bank ID : ")
obj = ExcelParser()
obj.config = conf
print(obj.extract(file_name))
obj1 = BankDataWriterBase()
obj1.output_path = out_path
obj1.bank_identifier = bank_id
print(obj1.write_file(file_name))
After seeing some of the answers i changed my code like the following
import pandas as pd
class ExcelParser:
def __init__(self):
self.config = []
def extract(self, file_name):
raw_excel=pd.read_excel(file_name,sheet_name=None, na_values= None, keep_default_na=False)
return [x for k, v in raw_excel.items() for x in v[v.columns.intersection(conf)].to_dict(orient='records')]
class BankDataWriterBase:
def __init__(self,file_name,out_path,bank_id):
self.input_path = file_name
self.output_path = out_path
self.bank_identifier = bank_id
def write_file(self, file_name:str):
res = True
return res
class BankDataWriterImpl(BankDataWriterBase):
def __init__(self, file_name, out_path, bank_id):
super().__init__(file_name, out_path, bank_id)
def extrac_json(self, file_name):
pass
if __name__ == "__main__":
conf = list(input("ENTER THE LIST HERE : ").split(','))
file_name = input("Enter the full input path here : ")
out_path = input("Enter the full path for the output : ")
bank_id = input("Enter the Bank ID : ")
obj = ExcelParser()
obj.config = conf
print(obj.extract(file_name))
obj1 = BankDataWriterBase()
obj1.output_path = out_path
obj1.bank_identifier = bank_id
print(obj1.write_file(file_name))