dolor.util.attr_dict

Contains AttrDict

class AttrDict(name_or_elems=None, **kwargs)[source]

Bases: collections.abc.MutableMapping

A wrapper around dict that also lets you access keys as attributes.

Parameters
  • name_or_elems (str or dict, optional) –

    If a str, then it will generate a new type with that name that inherits from AttrDict.

    If a dict, then it will use it as its underlying dictionary.

    If unspecified, then the initial underlying dictionary will be empty.

  • **kwargs – Will be used with dict.update() to update the underlying dictionary.

Examples

>>> import dolor
>>> MyAttrDict = dolor.util.AttrDict("MyAttrDict")
>>> MyAttrDict.__name__
'MyAttrDict'
>>> x = MyAttrDict(y=0)
>>> x.y
0
>>> x["y"]
0