Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Access a global object by its name than module

$
0
0

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?


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>