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:
parent
ed70e7a2f9
commit
a89d3dcd06
1 changed files with 13 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue