Here I have an example dictionary of functions:
d = {
'1' : f
'2a' : g
'2b' : h
'3' : i
...
}
Where some functions take no arguments and the rest always take the same arguments a, b
.
def f(a, b): ...
def g(): ...
def h(a, b): ...
def i(): ...
How do I call a function from this dictionary with/without arguments depending on if the function takes arguments?
i.e. With an arbitrary key x
.
if [d[x] takes arguments]:
d[x](a, b)
else:
d[x]()
Note: have to run out for an hour, so won't be able to reply straight away.