I have a peculiar problem at hand. There is an excel workbook and I am able to extract the sheet names as follows:
import xlrd
xls = xlrd.open_workbook(r'<path_to_your_excel_file>', on_demand=True)
sheet_names = [xls.sheet_names()]
I also have a set of funtions defined for each sheet. And the name of the function is same as the names of the sheets (abc, pqr, def,lmn) and a suffix of worksheet along with it. The number of input parameters are identical for each of these functions. i.e.
def abc_worksheet(arg1, arg2):
# returns abc_cleaned_csv
pass
def pqr_worksheet(arg1, arg2):
# returns pqr_cleaned_csv
pass
def def_worksheet(arg1, arg2):
# returns def_cleaned_csv
pass
def lmn_worksheet(arg1, arg2):
# returns lmn_cleaned_csv
pass
However it is unknown that in each workbook how many of these sheets would be present, i.e. today's workbook has worksheets (abc, pqr) and yesterday's workbook had worksheets (pqr, def, lmn).
What is the most pythonic way to call the processing functions according to the worksheets for any workbook?
I tried function dictionary mapping. But I am not able to call the fucntions dynamically and I feel it is not optimised.
func_dict = {'abc' : abc_worksheet
,'pqr' : pqr_worksheet
,'def' : def_worksheet
,'lmn' : lmn_worksheet}
for ele in sheet_names:
func_dict[ele](arg1, arg2)
Please suggest.