diff docs/introduction.rst @ 315:21fa4b4bfdaa

Docu: .getvarl() and .getvarl_s()
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 05 May 2021 01:41:01 +0200
parents dc4280451e0c
children fe2e28e5fd08
line wrap: on
line diff
--- a/docs/introduction.rst	Wed May 05 01:32:07 2021 +0200
+++ b/docs/introduction.rst	Wed May 05 01:41:01 2021 +0200
@@ -201,30 +201,54 @@
 Getting configuration variables
 -------------------------------
 
-Get a -- possibly interpolated -- configuration variable's value with::
+Get a -- possibly interpolated -- configuration variable's value with ::
 
     value1 = config.getvar_s("key1")
+    value2 = config.getvar_s("key1.subkey2")
 
-Get a raw configuration variable's value with::
+or equivalently with ::
+
+    value1 = config.getvarl_s("key1")
+    value2 = config.getvarl_s("key1", "subkey2")
+
+Get a raw configuration variable's value with ::
 
     value1_raw = config.getvar("key1")
+    value2_raw = config.getvarl("key1.subkey2")
+
+or equivalently with ::
+
+    value1_raw = config.getvarl("key1")
+    value2_raw = config.getvarl("key1", "subkey2")
 
 Because the configuration is not only a plain list of but a tree of
-key-value pairs you will want to fetch them by separating the individual
-level keys with a point ``.``.
+key-value pairs you will want to fetch a nested configuration value
+using two access methods:
+
+  :py:meth:`.Configuration.getvar` and :py:meth:`.Configuration.getvar_s`
+
+    Use a single key variable where the invidual level keys are joined
+    using a dot (``.``)
+
+  :py:meth:`.Configuration.getvarl` and :py:meth:`.Configuration.getvarl_s`
+
+    Use just positional Python arguments for each level key
 
 Looking at the example in chapter :ref:`yaml-files` -- when calling
 ``config.getvar_s("tree1.tree2.key4")`` you will get the value
 ``get this as `tree1.tree2.key4'``.
 
-This is true for both methods :py:meth:`.Configuration.getvar` and
-:py:meth:`.Configuration.getvar_s`.
+Alternatively ``config.getvarl_s("tree1", "tree2", "key4")`` can be called
+with the very same result.
 
-Both methods also perform direct :ref:`variable-interpolation` and handle
-:ref:`variable-namespaces`. Filtering is not supported. So -- the
-variable name arguments of :py:meth:`.Configuration.getvar` and
-:py:meth:`.Configuration.getvar_s` are of the form
-``[namespace:]variable``.
+All four methods also perform direct :ref:`variable-interpolation` and
+handle :ref:`variable-namespaces` -- yet in different ways.
+Filtering is not supported.
+So -- the variable name arguments of :py:meth:`.Configuration.getvar`
+and :py:meth:`.Configuration.getvar_s` are of the form
+``[namespace:]variable`` where for :py:meth:`.Configuration.getvarl`
+and :py:meth:`.Configuration.getvarl_s` the namespace is given as
+optional keyword parameter `namespace`.
 
 
 .. _merging-deletions:
@@ -314,11 +338,15 @@
 Examples
 ~~~~~~~~
 
-::
+Both ::
 
      config.getvar("OS:cwd")
 
-yields the current working directory as :py:func:`os.getcwd` does.
+or ::
+
+     config.getvarl("cwd", namespace="OS")
+
+yield the current working directory -- just as :py:func:`os.getcwd` does.
 
 
 .. _variable-interpolation:
@@ -327,8 +355,9 @@
 ----------------------
 
 Configuration variable values that are read with
-:py:meth:`.Configuration.getvar_s` are subject to variable
-interpolation. The general syntactic pattern for this is::
+:py:meth:`.Configuration.getvar_s` or :py:meth:`.Configuration.getvarl_s`
+are subject to variable interpolation.
+The general syntactic pattern for this is::
 
     {{[namespace:]variable[|filter[|filter...]]}}
 
@@ -338,6 +367,7 @@
 
 Variables are expanded *lately* at runtime -- exactly when calling
 :py:meth:`.Configuration.getvar_s`,
+:py:meth:`.Configuration.getvarl_s`,
 :py:meth:`.Configuration.substitute_variables_in_obj` or
 :py:meth:`.Configuration.expand_variable`