import json def getConfig(label): with open("config.json", "r") as f: return json.load(f)[label] # TODO error handling def setConfig(label, value, new=False): with open("config.json", "r") as f: config = json.load(f) if new and (label in config): # Setting is not new! # TODO return False if not new and (label not in config): # Tried to update a setting which is new! # TODO return False config[label] = value with open("config.json", "w") as f: json.dump(config, f) return True