misc.store_dict(): Add function

Add a store_dict() function to write the contents of a mapping to
a file as JSON, using the same formatting as dump_dict().

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-31 14:40:45 +02:00
commit a89d3dcd06
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -251,6 +251,19 @@ def dump_dict( # export
log.log(prio, f'| {line}', caller = caller)
log.log(prio, f'`{header}', caller = caller)
def store_dict(path: str, d: Mapping[str, Any]) -> None: # export
import json
with open(path, 'w') as f:
f.write(
json.dumps(
d,
sort_keys = True,
ensure_ascii = False,
indent = 4,
separators = (',', ': '),
)
)
def dump( # export
prio: int, objects: Iterable[Any], *args: Any, **kwargs: Any
) -> None: