Dictionaries¶
There are a few utility dictionaries available. All of them inherit from the
base dict
class, and can be used as drop-ins for the standard dict
type. There are a few “primitive” base types that are then composed to
more complex types. To use these types, import kutils.dicts
.
AttrDict
: this dictionary provides access to the keys as attributes.NoneDict
: this dictionary returnsNone
for non-existent keys. This means it will not throw aKeyError
for top-level keys; note that nested dictionaries may not be `NoneDict`s.StrDict
: this dictionary returns an empty string for non-existent keys.DictDict
: this dictionary returns an emptyStrDict
for non-existent keys. This is mostly useful for values that are nested dictionaries of keys.AttrNoneDict
: this is a composition of theAttrDict
and theNoneDict
: it provides access to its keys as attributes, and returnsNone
for missing keys or attributes; this means missing top-level keys and attributes will not throwKeyError
orAttributeError
.AttrDictDict
: this is a composition of theAttrDict
andDictDict
: it provides access to its keys as attributes, and returns an emptyStrDict
for missing keys or attributes; this means missing top-level keys and attributes will not throwKeyError
orAttributeError
.