pyexperiment.utils.HierarchicalMapping

Provide flat, point separated interface to nested mappings

As the zen of python says, flat is better than nested. In many cases, however, it makes sense to store data in a nested data structure. To bridge the gap, the HierarchicalMapping defines an abstract base class for data structures that can be treated like an ordinary mapping from strings to values, but with the advantage that the values for keys containing a level separator, e.g., “level1.level2.level3” are stored in a nested hierarchy of mappings.

Written by Peter Duerr

class pyexperiment.utils.HierarchicalMapping.HierarchicalDict[source][source]

Instance of the HierarchicalMapping based on dict

class pyexperiment.utils.HierarchicalMapping.HierarchicalMapping[source][source]

ABC for flat mutable mappings where all keys are strings.

Levels of hierarchy are indicated by a separator character and the storage is implemented as a hierarchy of nested Mutable mappings.

SECTION_SEPARATOR = u'.'[source]

Separates the hierarchy levels

__delitem__(key)[source][source]

Delete an item

__getitem__(key)[source][source]

Get an item

__iter__()[source][source]

Need to define __iter__ to make it a MutableMapping

__len__()[source][source]

Returns the number of entries in the mapping

__repr__()[source][source]

Get a representation of the mapping

__setitem__(key, value)[source][source]

Set an item

base_keys()[source][source]

Returns the keys of the first level of the mapping

get(key, default=None)[source][source]

Get the key or return the default value if provided

get_or_set(key, value)[source][source]

Either gets the value associated with key or set it This can be useful as an easy way of

merge(other)[source][source]

Merge in another mapping, giving precedence to self

section_keys()[source][source]

Returns the keys of the sections (and subsections) of the mapping

show()[source][source]

Pretty-prints the content of the mapping

class pyexperiment.utils.HierarchicalMapping.HierarchicalOrderedDict[source][source]

Instance of the HierarchicalMapping based on an OrderedDict.