Example
I have a test.py with this one function
def hello():
print("hello, world")
Problem
I want to import this module in another module, and then run the script. However, the module will be given as command line argument and thus I have to execute the function only knowing the name of the function as a string. How can I execute it?
What I want to do
python/pseudocode
def main():
import test
function_name = "hello"
run code test["hello"]()
Things I have tried
- Envoking the function through the modules locals(), but I haven't found a way to make it work.
- reading the module as string and using exec. However, I don't want to parse the whole module to find its functions etc
Any help is appreciated