python-configuration icon indicating copy to clipboard operation
python-configuration copied to clipboard

How can I change the config value and write it back to the config file?

Open programus opened this issue 2 years ago • 0 comments

This is a great library and I am using it in my project.

I am using this to read 3 configs, a yml, an internal dict and an optional json. I want to use the last json file as a customizable config and allow user to change the value through UI.

How can I change the config value and write it back to the json file?

This is the code I build the ConfigurationSet:

config_list = [
    cfg_lib.config_from_yaml(util.resource_path('res/secret.yml'), read_from_file=True),
    cfg_lib.config_from_python(internal_config, separator='___'),
]

try:
    if os.path.exists(internal_config.local_config_file):
        config_list.append(cfg_lib.config_from_json(internal_config.local_config_file))
    else:
        logging.warning(f'config file {internal_config.local_config_file} does not exits yet.')
except json.JSONDecodeError:
    logging.exception(f'config file {internal_config.local_config_file} is bad json format.')
finally:
    config = cfg_lib.ConfigurationSet(*config_list)

programus avatar May 09 '22 05:05 programus