Move python files into py dir
This commit is contained in:
parent
22ad36fb09
commit
129721eb50
9 changed files with 2 additions and 2 deletions
20
py/files.py
Normal file
20
py/files.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
"""File operation helpers"""
|
||||
import json
|
||||
import shutil
|
||||
|
||||
|
||||
def load(file: str) -> dict:
|
||||
"""Load a json file directly as a dict"""
|
||||
with open(file) as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def save(file: str, content: dict):
|
||||
"""
|
||||
Save out a content dictionary to a file
|
||||
Stores it in an intermediary file first incase the dump fails
|
||||
"""
|
||||
intermediate = file + ".nxt"
|
||||
with open(intermediate, "w") as f:
|
||||
json.dump(content, f, indent=4)
|
||||
shutil.move(intermediate, file)
|
Loading…
Add table
Add a link
Reference in a new issue