Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Accessing parameters using string only #14

Open
adrianohrl opened this issue May 30, 2020 · 0 comments
Open

Accessing parameters using string only #14

adrianohrl opened this issue May 30, 2020 · 0 comments

Comments

@adrianohrl
Copy link

adrianohrl commented May 30, 2020

Is it possible to access the parameters of a config file via string only?

Consider a config file with the content below:

{
  "level_0": {
    "level_1": {
      "param_0": "value_0"
    }
  }
}

The param_0 parameter could be accessed as bellow:

config = jsoncfg.load_config('config.json')

param_0 = config.get('level_0.level_1.param_0', 'default_value')

# or
if 'level_0.level_1.param_0' in config:
  param_0 = config['level_0.level_1.param_0']

print(param_0)

This would be a dict-like interface. However, one pair of brackets only would be necessary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant