add default to open_json_file

This commit is contained in:
jomo
2014-07-27 06:01:52 +02:00
parent efc3ee439c
commit d58d975910
2 changed files with 5 additions and 3 deletions

View File

@@ -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):