David542 David542 - 1 year ago 91
Python Question

Call imported function in python using string

I have a list of the names of imported functions, which I can call as follows:

from myfile import function1
from myfile import function2


How would I call the functions from a list of names? For example:

fns = ['function1', 'function2']
for fn in fns:

How would I do the above properly?

Answer Source

don't use a list of strings, just store the functions in the list:

fns = [function1, function2]
for fn in fns:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download