adf#

class NestedDict(data=None)[source]#

Bases: dict

get(*keys)[source]#

Get a nested value from this dict.

Parameters:

keys (Tuple[Any]) – an unpacked tuple of keys used to access the value.

Return type:

Any

Example

>>> nd = NestedDict()
>>> nd.set('a', 'b', 'c', 15, priority=1)
>>> nd
{'a': {'b': {'c': 15}}}
>>> nd.get('a', 'b')
{'c': 15}
>>> nd.get('a', 'b', 'c')
15
set(*args, priority=0)[source]#

Override of the standard dict.set method allowing for setting a nested key in one call.

Parameters:
  • args (Tuple[Any]) – an unpacked tuple of firstly keys and then the value to be set.

  • priority (float) – the priority for setting this value. If the given priority is higher than a previously set priority we set the value, otherwise we ignore it.

Raises:

ValueError – If there are not at least 2 arguments provided.

Examples

>>> nd = NestedDict()
>>> nd.set('a', 'b', 'c', 15, priority=1)
>>> nd
{'a': {'b': {'c': 15}}}
>>> nd.set('a', 'b', 'c', 'overwritten?', priority=0)
>>> nd
{'a': {'b': {'c': 15}}}
>>> nd.get('a', 'b', 'c')
15
ensure_list(x)#
read_data(reader, SCF0_reader=None, output=None)[source]#
sqrt(x, /)#

Return the square root of x.