drytoml.locate module¶
Utilities to simplify deep getitem calls.
-
drytoml.locate.
deep_del
(document, final, *breadcrumbs)¶ Delete content located deep within a data structure.
- Parameters
document – Where to remove the content from.
final – Last key required to locate the element to be deleted.
breadcrumbs – The path to walk from the container root up to the parent ob the object to be deleted.
Examples
Examples should be written in doctest format, and should illustrate how to use the function.
>>> container = { ... "foo": [ ... {}, ... {"bar": "delete_me"} ... ] ... } {'foo': [{}, {'bar': 'delete_me'}]} >>> deep_del(container, "bar", ["foo", 1]) >>> container {'foo': [{}, {}]}
-
drytoml.locate.
deep_find
(container: Union[str, list, dict], extend_key: str, breadcrumbs: Optional[List[str]] = None) → Generator[List[tomlkit.items.Key], type, None]¶ Walk a data structure to yield all occurences of a key.
- Parameters
container – Where to look for the key.
extend_key – The key to look for.
breadcrumbs – The sequence of walked keys to the current position.
- Returns
The container type
- Yields
- Tuple containing (breadcrumbs, content) where extend_key
was found.