dictutils.ops.ensure_pathΒΆ
- dictutils.ops.ensure_path(d, path, *, factory=<class 'dict'>)[source]ΒΆ
Ensure nested path exists and return the container at that path.
- Parameters:
- Return type:
- Returns:
The container at the specified path
Example
>>> import json >>> data = {} >>> container = ensure_path(data, "user.profile.settings") >>> container["theme"] = "dark" >>> print(json.dumps(data, indent=4)) { "user": { "profile": { "settings": { "theme": "dark" } } } }