I have a function that has to call other functions, with a not-fixed number and type of arguments, that I want to set in a dictionary.
Something like this:
def main_function(list_of_subfunctions_to_call):
functions_to_call = {'fcname1': {'method': 'fc1', 'args': ('var1')},
'fcname2': {'method': 'fc2', 'args':('var2', 'var3')}}
var1 = None
var2 = None
var3 = None
for fc in list_of_subfunctions_to_call:
functions_to_call[fc]['method'](fc['args'])
Of course this doesn't work because the args are strings and not actual variables.
I guess the solution may be related with named tuples but I can't figure out exactly how.
Also, I'm not sure whether this is a good practice, or there is a better way to achieve this same result.
args
being strings, not values.functions_to_call = {'fcname1': {'method': 'fc1', 'args': {'var1': var1}}, 'fcname2': {'method': 'fc2', 'args':{'var2':var2, 'var3':var3})}}
And to define the variables before the dictionary('var1')
needs a comma to make it a tuple:('var1',)