utils.py
390 Bytes
import json
def save_object_to_file(obj, filename):
with open(filename, 'w', encoding='utf-8') as f:
f.write(json.dumps(obj))
def load_object_from_file(filename):
try:
with open(filename, 'r', encoding='utf-8') as f:
return json.loads(f.read())
except Exception as e:
print('Error opening file: ' + filename)
print(e)
return None