-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (28 loc) · 895 Bytes
/
utils.py
File metadata and controls
37 lines (28 loc) · 895 Bytes
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 saveVar(var, file_path):
"""
save_var saves a var to a specified filePath
INPUT:
var: the variable to be saved
file_path: the filepath you want to save the var, for example data/.../var.pckl. If the path does not exist, it creates it
"""
directory = os.path.dirname(file_path)
if not os.path.exists(directory): # makes the directory if it does not exist
os.makedirs(directory)
# uses pickle to serialize and save the variable var
pickle_out = open(file_path, "wb")
pickle.dump(var, pickle_out)
pickle_out.close()
def loadVar(file_path):
"""
LOADVAR loads a var from a specified filePath
INPUT:
filePath: where the variable is
OUTPUT:
var: the variable loaded
"""
pickle_in = open(file_path, "rb")
var = pickle.load(pickle_in)
pickle_in.close()
return var