saving and loading objects from file using jsonpickle
问题 I have the following simple methods for writing a python object to a file using jsonpickle: def json_serialize(obj, filename, use_jsonpickle=True): f = open(filename, 'w') if use_jsonpickle: import jsonpickle json_obj = jsonpickle.encode(obj) f.write(json_obj) else: simplejson.dump(obj, f) f.close() def json_load_file(filename, use_jsonpickle=True): f = open(filename) if use_jsonpickle: import jsonpickle json_str = f.read() obj = jsonpickle.decode(json_str) else: obj = simplejson.load(f)