summaryrefslogtreecommitdiff
path: root/helpers.py
diff options
context:
space:
mode:
authorjomo <github@jomo.tv>2014-07-27 06:01:52 +0200
committerjomo <github@jomo.tv>2014-07-27 06:01:52 +0200
commitd58d975910b5840ec3119f52bfa42fbbc58fc038 (patch)
tree366ba20ea9c1edc9271261afda3a928e4bee751e /helpers.py
parentefc3ee439ccdb0adad1544f32b60fa0bc0340bb6 (diff)
add default to open_json_file
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/helpers.py b/helpers.py
index f46237c..25b4091 100644
--- a/helpers.py
+++ b/helpers.py
@@ -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):