-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_abrev.py
35 lines (32 loc) · 1.06 KB
/
parse_abrev.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
#!/usr/bin/env python
import glob, os
class parse_abrev():
def __init__(self,pathabrev):
'''
initializethe parse abrev class
'''
self.pathabrev=pathabrev
self.dicabrev={}
self.listfiles=[]
def parse(self):
'''
Parse the abrev files and put the result in a dictionary
Return the dictionary
'''
for file in glob.glob(self.pathabrev + '/*.tmp'):
#print(file)
self.listfiles.append(file)
for fil in self.listfiles:
base=os.path.basename(fil)
filename=os.path.splitext(base)[0]
#print(filename)
#print('filename ' + filename)
self.dicabrev[filename]={}
with open(fil) as f:
for line in f:
line = line.rstrip()
line = line.split('\t')
if(len(line)==2):
self.dicabrev[filename][line[0]]=line[1]
#print(filename+' '+line[0]+' '+line[1])
return self.dicabrev