-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
33 lines (28 loc) · 1.02 KB
/
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
import os
import pprint
import copy
def check_path(file_path):
if not os.path.exists(file_path):
os.makedirs(file_path)
def save_dict(file_path, file_name, dict):
check_path(file_path)
data_path = os.path.join(file_path, file_name)
file = open(data_path, 'w')
file.write(str(dict))
file.close()
def load_dict(file_path, file_name):
data_path = os.path.join(file_path, file_name) if file_path is not None else file_name
assert os.path.isfile(data_path), '{} file does not exist.'.format(data_path)
file = open(data_path, 'r')
return eval(file.read())
def save_list(file_path, file_name, list_data):
check_path(file_path)
data_path = os.path.join(file_path, file_name)
file = open(data_path, 'w')
file.write(str(list_data))
file.close()
def load_list(file_path, file_name):
data_path = os.path.join(file_path, file_name)
assert os.path.isfile(data_path), '{} file does not exist.'.format(data_path)
file = open(data_path, 'r')
return eval(file.read())