-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
38 lines (28 loc) · 817 Bytes
/
util.py
File metadata and controls
38 lines (28 loc) · 817 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
38
import pickle
import os
def read_txt(filename):
res = list()
with open(filename, 'rb') as f:
for line in f:
res.append(line.decode('utf-8').strip())
return res
def read_txt_to_dict(filename):
labels = read_txt(filename)
#
label_dict = {}
for i, label in enumerate(labels):
label_dict[label] = i
return label_dict
def save_to_pickle(filename, content):
dir_path = os.path.dirname(filename)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
with open(filename, 'wb') as f:
pickle.dump(content, f)
def save_to_pickle(filename, content):
with open(filename, 'wb') as f:
pickle.dump(content, f)
def read_pickle(filename):
pkl_file = open(filename, 'rb')
data = pickle.load(pkl_file)
return data