Ive searched the website and this website and could not find an answer to this problem. I am sure that he is right in front of me, but I cannot find him.
I need to be able to import a module based on a string. Then execute the function inside this module when passing the arguments.
I can import based on the string and then execute using eval (), but I know this is not the best way to handle this. I also cannot pass arguments this way.
My current module, which will be installed based on the string, is called TestAction.py and lives in the Tasks folder. This is the contents of TestAction.py:
def doSomething(var): print var
This is the code that I execute to import TestAction and execute.
module = "Tasks.TestAction" import Tasks mymod = __import__(module) eval(module + ".doSomething()")
How can I make this code # 1 not use eval() and # 2 pass the var argument to doSomething() ?
Thanks in advance!
source share