Mercurial > hgrepos > Python > libs > ConfigMix
comparison docs/introduction.rst @ 375:baedd2031074
Docs: Introduce the newly introduces access methods
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 11 Jul 2021 17:28:31 +0200 |
| parents | bd28fb4565e1 |
| children | d7dcd76c262a |
comparison
equal
deleted
inserted
replaced
| 374:4d7ad20cb8f9 | 375:baedd2031074 |
|---|---|
| 221 value1_raw = config.getvarl("key1") | 221 value1_raw = config.getvarl("key1") |
| 222 value2_raw = config.getvarl("key1", "subkey2") | 222 value2_raw = config.getvarl("key1", "subkey2") |
| 223 | 223 |
| 224 Because the configuration is not only a plain list of but a tree of | 224 Because the configuration is not only a plain list of but a tree of |
| 225 key-value pairs you will want to fetch a nested configuration value | 225 key-value pairs you will want to fetch a nested configuration value |
| 226 using two access methods: | 226 using two access basic methods: |
| 227 | 227 |
| 228 :py:meth:`.Configuration.getvar` and :py:meth:`.Configuration.getvar_s` | 228 :py:meth:`.Configuration.getvar` and :py:meth:`.Configuration.getvar_s` |
| 229 | 229 |
| 230 Use a single key variable where the invidual level keys are joined | 230 Use a single key variable where the invidual level keys are joined |
| 231 using a dot (``.``) | 231 using a dot (``.``) |
| 232 | 232 |
| 233 :py:meth:`.Configuration.getvarl` and :py:meth:`.Configuration.getvarl_s` | 233 :py:meth:`.Configuration.getvarl` and :py:meth:`.Configuration.getvarl_s` |
| 234 | 234 |
| 235 Use just positional Python arguments for each level key | 235 Use just positional Python arguments for each level key |
| 236 | |
| 237 Also there exist variants of the basic access methods that coerce | |
| 238 returned variables into :py:class:`int` or :py:class:`bool` types | |
| 239 (:py:meth:`.Configuration.getintvar_s`, | |
| 240 :py:meth:`.Configuration.getboolvar_s`) | |
| 241 | |
| 242 And with :py:meth:`.Configuration.getfirstvar`, | |
| 243 :py:meth:`.Configuration.getfirstvar_s`, | |
| 244 :py:meth:`.Configuration.getfirstintvar_s` and | |
| 245 :py:meth:`.Configuration.getfirstboolvar_s` there exist variants that | |
| 246 accept a *list* of possible variables names and return the first one | |
| 247 that is found. | |
| 236 | 248 |
| 237 Looking at the example in chapter :ref:`yaml-files` -- when calling | 249 Looking at the example in chapter :ref:`yaml-files` -- when calling |
| 238 ``config.getvar_s("tree1.tree2.key4")`` you will get the value | 250 ``config.getvar_s("tree1.tree2.key4")`` you will get the value |
| 239 ``get this as `tree1.tree2.key4'``. | 251 ``get this as `tree1.tree2.key4'``. |
| 240 | 252 |
