diff options
author | jomo <github@jomo.tv> | 2014-07-27 06:01:52 +0200 |
---|---|---|
committer | jomo <github@jomo.tv> | 2014-07-27 06:01:52 +0200 |
commit | d58d975910b5840ec3119f52bfa42fbbc58fc038 (patch) | |
tree | 366ba20ea9c1edc9271261afda3a928e4bee751e /helpers.py | |
parent | efc3ee439ccdb0adad1544f32b60fa0bc0340bb6 (diff) |
add default to open_json_file
Diffstat (limited to 'helpers.py')
-rw-r--r-- | helpers.py | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -119,16 +119,18 @@ def played_before(player): return True -def open_json_file(filename): +def open_json_file(filename, default): """ opens the given json file and returns an object or returns None on error filename is the path + name of the file. """ + data = None try: with open(filename) as obj: - return json_loads(obj.read()) + data = json_loads(obj.read()) except Exception, e: error("Failed to read from %s: %s" % (filename, e)) + return (default if data is None else data) def save_json_file(filename, obj): |