lair.utils.DotDict#

class lair.utils.DotDict[source]#

Bases: dict

A dictionary whose keys are also attributes (d.key as well as d["key"]).

A dictionary stored in a DotDict is wrapped when it is first read, so d.a.b works at any depth, and d.a.b = 2 changes d.

See also

dict

What it extends.

Examples

>>> from lair.utils import DotDict
>>> d = DotDict({"site": {"name": "SLC", "elevation": 1289}})
>>> d.site.name
'SLC'
>>> d.site.elevation = 1300
>>> d["site"]["elevation"]
1300
>>> d.missing
Traceback (most recent call last):
    ...
AttributeError: missing