Skip to content Skip to sidebar Skip to footer

Python Creating Dynamic Global Variable From List

I am trying to make generic config, and thus config parser. There are two config files say A and B. I want to parse sections and make global values from them according to hardcoded

Solution 1:

A simple way to solve this issue is in your application package within the __init__.py you can do something similar to the following:

app_config = read_config()

defread_config():
    configparser = ConfigParser.RawConfigParser()
    configparser.read(some_config_filename)
    return configparser.as_dict() #An imaginery method which returns the vals as dict.

The "app_config" variable can be imported into any other module within the application.

Post a Comment for "Python Creating Dynamic Global Variable From List"