Skip to content

Instantly share code, notes, and snippets.



Last active May 21, 2016
What would you like to do?
{"id": 1}
# coding: utf-8
import json
def load_conf(conf_file="conf.json"):
with open(conf_file) as conf:
return json.load(conf)
except ValueError:
return {}
def save_conf(data, conf_file="conf.json"):
conf = load_conf(conf_file)
with open(conf_file, "w") as file_:
json.dump(conf, file_)
if __name__ == '__main__':
from tempfile import NamedTemporaryFile
with NamedTemporaryFile() as temp:
save_conf({'id': 1},
data = load_conf(
assert data == {'id': 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment