The file module_x
has
module_x.py
A = 'x'
And the following script will print 'x' from module_x.py
, which is what I need.
A = 'a'
from module_x import *
print(A) # x
However, I need to dynamically import the module so I use importlib for it. However, the following code prints 'a'.
from importlib import import_module
A = 'a'
m = 'module_x' # m will be passed as a parameter
x = import_module(m)
print(A) # a
The value of x.A
is 'x', but I want the import_module()
to assign A to 'x'.