I try to import a module with exec("import __ as tmp") in python:
def prepare(self):
for modName in self._config.modules.keys():
print(locals())
exec("import {} as tmp".format(modName))
print(locals())
self._moduleInst[modName] = tmp
Output is:
{'modName': 'time', 'self': <pyo.Server.Server object at 0x000001CA17DFB550>}
{'modName': 'time', 'self': <pyo.Server.Server object at 0x000001CA17DFB550>, 'tmp': <module 'time' (built-in)>}
Traceback (most recent call last):
File "[...]", line 3, in <module>
startServer(None)
File "[...]", line 10, in startServer
server.prepare()
File "[...]", line 15, in prepare
self._moduleInst[modName] = tmp
NameError: name 'tmp' is not defined
I get an NameError exception, cause python cannot find tmp. If I print out all local variables, tmp is defined...
Has anybody an idea what I'm doing wrong? Thank you!