Config¶
-
class
lsst.daf.butler.
Config
(other=None)¶ Bases:
collections.abc.MutableMapping
Implements a datatype that is used by
Butler
for configuration parameters.It is essentially a
dict
with key/value pairs, including nested dicts (as values). In fact, it can be initialized with adict
. This is explained next:Config extends the
dict
api so that hierarchical values may be accessed with delimited notation or as a tuple. If a string is given the delimiter is picked up from the first character in that string. For example,foo.getValue(".a.b.c")
,foo["a"]["b"]["c"]
,foo["a", "b", "c"]
,foo[".a.b.c"]
, andfoo["/a/b/c"]
all achieve the same outcome. If the first character is alphanumeric, no delimiter will be used.foo["a.b.c"]
will be a single keya.b.c
as willfoo[":a.b.c"]
. Unicode characters can be used as the delimiter for distinctiveness if required.If a key in the hierarchy starts with a non-alphanumeric character care should be used to ensure that either the tuple interface is used or a distinct delimiter is always given in string form.
Finally, the delimiter can be escaped if it is part of a key and also has to be used as a delimiter. For example,
foo[r".a.b\.c"]
results in a two element hierarchy ofa
andb.c
. For hard-coded strings it is always better to use a different delimiter in these cases.Note that adding a multi-level key implicitly creates any nesting levels that do not exist, but removing multi-level keys does not automatically remove empty nesting levels. As a result:
>>> c = Config() >>> c[".a.b"] = 1 >>> del c[".a.b"] >>> c["a"] Config({'a': {}})
Storage formats supported:
- yaml: read and write is supported.
Parameters: