-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.py
40 lines (26 loc) · 864 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pickle
import os
def save_obj(file_path, obj):
with open(file_path, 'wb') as handle:
pickle.dump(obj, handle, protocol=pickle.HIGHEST_PROTOCOL)
def load_obj(file_path):
with open(file_path, 'rb') as handle:
b = pickle.load(handle)
return b
def get_result_filepath(results_name, root='', subfolder=''):
res_path = os.path.join(root, 'results')
if not os.path.isdir(res_path):
os.mkdir(res_path)
subfolder_path = os.path.join(res_path, subfolder)
if not os.path.isdir(subfolder_path):
os.mkdir(subfolder_path)
taken = True
index = 0
filepath = None
while taken:
filepath = os.path.join(subfolder_path, 'r' + str(index) + '_' + results_name)
if os.path.isfile(filepath):
index += 1
else:
taken = False
return filepath