# funcs.py
def foo():
print('invoked')
# main.py
import funcs
name = 'foo'
funcs.name() # doesn't work
How to invoke a function that is dynamically selected and the name is stored in a string?
# funcs.py
def foo():
print('invoked')
# main.py
import funcs
name = 'foo'
funcs.name() # doesn't work
How to invoke a function that is dynamically selected and the name is stored in a string?
Use
eval(name + "()")
Like This
#funcs
def foo():
print('invoked')
# main.py
from funcs import foo
name = 'foo'
eval(name + "()")