If I declare these functions:
def f1(someval):
print(someval)
def f2(someval, someval2):
print(someval, someval2)
And if I have a dictionary that contains the functions as values:
input_dict = {"func1": f1, "func2": f2}
And I want to check if input from the user matches a key in the ditionary 'input_dict':
shell_input = 'shell~: '
for key,val in input_dict:
if key == shell_input:
input_dict[val](params)
How could I detect how many function parameters there are per each function being called and pass values to them, is it even possible (without declaring global variables)?
I am trying to avoid using chained if, elif, else logic in my code for example:
if shell_input == "func1":
f1(param)
elif shell_input == "func2":
f2(param1, param2)
#etc...
or is it okay to use chained if, elif, else logic in when checking input?
Aucun commentaire:
Enregistrer un commentaire