I have a module where I read a config file and store it into a variable.
Eg: myconfig.py
looks like:
cfg = {}def load(file_path): global cfg cfg = cfg_file_todict(file_path)
This load()
function is called in a main()
function (i.e. at beginning of the process).
I observe that the cfg
variable cannot be imported directly, but it has to accessed via the module name.
I.e., say I have a file a.py
where:
import myconfigprint(myconfig.cfg) # This prints the config properly across modules
But if I have:
from myconfig import cfgprint(cfg) # This prints None
Is there some way where even the second type of import can still retain the original variable? Or is there some other alternative to this?