I have a module object containing several function definitions. Here is a simplified example.
The source code (makes up the module "my_module")
def functionA():
print("hello")
def functionB():
functionA()
print("world")
The module is built with imp (I know it is depreciated, but my app is still on python 3.5)
ast_node = parse(source)
byte_code = compile(ast_node, 'my_module', 'exec')
my_module = imp.new_module('my_module')
exec(byte_code, __builtins__, my_module.__dict__)
I am trying to run functionB()
using exec
and passing in the full module __dict__
as the local dictionary. (I've also tried passing it in as the global dictionary without any luck)
exec("functionB()", None, my_module.__dict__)
The error I see is NameError: name 'functionA' is not defined
Is it possible to extend the local (or even global) scope to the executing function?