You could use a dictionary as a dispatch-table, and namedtuples to store a function & argument pairing.
from collections import namedtuple
def funcA(arg1, arg2):
print(f'I am funcA and you gave me {arg1} and {arg2}')
def funcB(arg):
print(f'I am funcB and you gave me {arg}')
def funcC():
print(f'I am funcC')
def funcD():
print(f'I am funcD')
def funcE():
print(f'I am funcE')
OptionPairing = namedtuple('OptionPairing', ['f', 'args'])
dispatch = {
1: OptionPairing(funcA, [True, False]),
2: OptionPairing(funcB, [True]),
3: OptionPairing(funcC, []),
4: OptionPairing(funcD, []),
5: OptionPairing(funcE, [])
}
for i in range(1, 6):
choice = dispatch[i]
x = choice.f(*choice.args)
Running this, then, gives the following results:
I am funcA and you gave me True and False
I am funcB and you gave me True
I am funcC
I am funcC
I am funcE
If you want to specify yourself what arguments to pass to your function, simply this will suffice:
dispatch = {
1: funcA,
2: funcB,
3: funcC,
4: funcD,
5: funcE,
}
Then call your function like so:
dispatch[option](args)
Making sure to pass the arguments args, as a list, since the number of arguments is variadic.
option. You can't just writesome_dict[option](...).