I have a module like this
# mymodule.py
def myfun():
print "hello"
being called like this
# main.py
import mymodule
def run(funcname):
mymodule[funcname]()
in a directory structured like this
./
|
|--mymodule/
|--__init__.py
|--mymodule.py
|--main.py
When I call the run method of main.py like this
run("myfun")
I get this error:
TypeError: 'module' object has no attribute '__getitem__'
Understandably. I wouldve been surprised if this worked. The thing is, I need to be able to call a method of a module by string. Is this possible?