-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_handler.py
44 lines (31 loc) · 1.04 KB
/
io_handler.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
38
39
40
41
42
43
44
import os
_data = "data"
_file_name = "dict.csv"
_abs_path = os.path.abspath(os.path.dirname(__file__))
_data_abs_path = os.path.join(_abs_path,_data)
def write_dictionary(my_dic):
if not os.path.isdir(_data_abs_path):
os.makedirs(_data_abs_path)
try:
with open(os.path.join(_data_abs_path,_file_name), 'w') as out_f:
for key, value in my_dic.items():
out_f.write("{} {}\n".format(key, value))
return True
except:
return False
def load_dictionary():
if not os.path.isdir(_data_abs_path):
return False
if not os.path.exists(os.path.join(_data_abs_path,_file_name)):
return False
with open(os.path.join(_data_abs_path,_file_name),'r') as in_f:
hu_en_dic = {}
en_hu_dic = {}
for line in in_f:
try:
hu, en = line.strip().split(" ")
hu_en_dic[hu] = en
en_hu_dic[en] = hu
except ValueError:
continue
return (hu_en_dic, en_hu_dic)