I was wondering if there was a way to dynamically import an entire module (equivalent to "import * some_module").
After some research on other posts I saw you could dynamically do "import some_module", but not pull the entire module.
In order to clarify my question,
some_module :
SOME_VARIABLE = 1
module a :
if(1 == 1):
__import__("some_module");
module b :
from module a import *
print(SOME_VARIABLE);
running this code returns an unrecognized variable exception, I would like to prevent that.
Motiviation :
Lets say I have a global module which imports multiple other module via a function that recieves an argument.
Example :
module a :
import_modules(modules_id):
if(modules_id == 1):
from module_c import *
from module_d import *
else :
from module_e import *
module b :
from module a import *
import_modules(1);
and I want to access all variables from module_c/d with explicit calling.
My actual problem :
I have an interface driver which interacts with different devices using different protocols (Each implemented via a different class), these protocols have certain similarities, for example : they both a have a CUSTOMER_STATUS dict (Which is defined in a protcol_a/b_global_def module which is imported by the specific protocol).
The problem I am encountering is that both protocols have variables with the same name, and since the interface driver needs to recognize them both I cant know which variable I am accessing from the program that is using the interface driver (Imports it).
Take in account that the program using the interface driver only knows dynamically which protocol it needs to use and I want to avoid importing the protocol global def manually inside the program (Even though I want to use its variables in the program).