ninjecto.utils.dictionary

Dictionary and namespaces related utilities.

Functions

  • update(): Recursively update a dictionary with another.
ninjecto.utils.dictionary.update(to_update, update_with)

Recursively update a dictionary with another.

Parameters
  • to_update (dict) – Dictionary to update.
  • update_with (dict) – Dictionary to update with.
Returns

The first dictionary recursively updated by the second.

Return type

dict

Classes

  • Namespace: Simple dictionary to object class.
class ninjecto.utils.dictionary.Namespace(*args, **kwargs)

Simple dictionary to object class.

Usage:

>>> from metrica.namespace import Namespace
>>> ns = Namespace(
...     {'one': 100},
...     {'two': 300},
...     {'two': 400, 'three': {'four': 400}},
...     one=200,
... )
>>> ns.two
400
>>> ns.one
200
>>> ns['two']
400
>>> ns['two'] = 300
>>> ns['two']
300
>>> ns.two = 700
>>> ns['two']
700
>>> ns.two
700
>>> ns.three.four
400
>>> ns['three'].four
400
>>> ns['three']['four']
400

Inheritance

Inheritance diagram of Namespace