HierarchicalDict#

Provides tools to handle / print hierarchical parameter dictionaries.

Example

>>> import ClearMap.Utils.HierarchicalDict as hdict
>>> d = dict(x = 10, y = 100, z = dict(a = 10, b = 20))
>>> print(hdict.get(d, 'z_a'))
10
>>>  hdict.set(d, 'z_c_q', 42)
>>> hdict.pprint(d)
x: 10
y: 100
z: dict
   a: 10
   b: 20
   c: dict
      q: 42
expand(parameter)[source]#
flatten(parameter)[source]#
get(parameter, key, default=None)[source]#

Gets a parameter from a dict, returns default value if not defined

Arguments

parameterdict

Parameter dictionary.

keyobject

Parameter key

defaultobject

Default value if parameter not defined.

Returns

valueobject

Parameter value for key.

join(*args)[source]#

Joins dictionaries in a consistent way

Arguments

argsdicts

The parameter dictionaries to join.

Returns

joindict

The joined dictionary.

pprint(parameter=None, head=None, **args)[source]#

Prints parameter settings in a formatted way.

Arguments

parameterdict

Parameter dictionary.

headstr or None

prefix of each line

args

Additional parameter values as key=value arguments.

prepend(parameter, key)[source]#

Adds a hierarchical key in front of all the parameter keys in a dictionary.

Arguments

parameterdict

Parameter dictionary.

keystr

Key to add in front of the dictionary keys.

Returns

prependdict

New dictionary with modified keys.

set(parameter, key=None, value=None, **kwargs)[source]#

Sets a parameter in a hierarchical dictionary.

Arguments

parameterdict

Parameter dictionary.

keyobject

Key in dictionary.

valueobject

Value to set.

kwargs

Key : value pairs.

Returns

parameterdict

Parameter dictionary.

write(parameter=None, head=None, **kwargs)[source]#

Writes parameter settings in a formatted way.

Arguments

parameterdict

Parameter dictionary.

headstr or None

Optional prefix of each line.

kwargs

Additional parameter values as key=value arguments.

Returns

stringstr

A formatted string with parameter info.