adding requests to conda install docs
[JPSSData.git] / saveload.py
blob3375cb9f418ca62aeebb2d52cea3f7f913af928a
1 # a simple utility to save to file and load back
2 import pickle
4 def save(obj,file):
5 """
6 :param obj: object to be saved
7 :param file: file name
8 """
9 with open(file,'wb') as f:
10 pickle.dump(obj,f,protocol=-1)
12 def load(file):
13 """
14 :param file: file name
15 :return: the object read
16 """
17 try:
18 # python 2
19 with open(file,'rb') as f:
20 return pickle.load(f)
21 except:
22 # python 3
23 with open(file,'rb') as f:
24 return pickle.load(f,encoding='latin1')