-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftools.py
33 lines (25 loc) · 957 Bytes
/
ftools.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
# ftools
# A collection of file utilities
import os
import pickle
def save_results(results, filename, directory=''):
# Ensure filename is just a filename, not a path
filename = os.path.basename(filename)
if directory != '':
directory = directory + "\\"
# Construct the full path safely
full_path = os.path.join(os.getcwd(), directory+filename)
with open(full_path, 'wb') as f:
pickle.dump(results, f)
print(f'results array saved to {filename}')
def load_plk_results(filename, directory=''):
# Ensure filename is just a filename, not a path
filename = os.path.basename(filename)
if directory == '':
# Construct the full path safely
full_path = os.path.join(os.getcwd(), filename)
else:
full_path = os.path.join(os.getcwd(), directory+"\\"+filename)
with open(full_path, 'rb') as f:
results = pickle.load(f)
return results