osc.utils.to_dotlist

to_dotlist(d, prf=())[source]

Iterate over a flattened dict using dot-separated keys.

Parameters
  • d – a hierarchical dictionary with strings as keys

  • prf (Tuple[str, ...]) – tuple of prefixes used for recursion

Notes

The type of d can be defined as StringDict, but it clashes with Sphynx: StringDict = Mapping[str, Union[Any, StringDict]].

Examples

Flatten a dict:

>>> print(*to_dotlist({'a': {'b': {}, 'c': 1, 'd': [2]}, 'x': []}), sep="\n")
('a.b', {})
('a.c', 1)
('a.d', [2])
('x', [])
Yields

Tuples of dot-separated keys and values. Call :func:dict on the returned iterator to build a flat dict.

Return type

Iterator[Tuple[str, Any]]