I have a list of functions and need to call a function, if that function exists in that list. Also, I need to call the function with a string.
I have tried doing something like this:
if "func1" in funcs:
funcs.__getitem__("func1")
but I can't get it right
funcs = [func1, func2, func3]
def func1: return 1
def func2: return 2
def func3: return 3
if "func1" in funcs:
# call func1 since it exists
I expect the output to be 1
, but I don't know how to call the function.
Also, this is not a duplicate because I won't call the function from a class.