-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrim.py
73 lines (62 loc) · 1.63 KB
/
trim.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import re
s_path = "G:\\200T-wire\\INT_X14Y100_wire.txt"
m_path = "G:\\200T-wire\\trimmed-raw.txt"
d_path = "G:\\200T-wire\\trimmed.txt"
origin = open(s_path, 'r', encoding = 'utf-8')
mid = open(m_path, 'w', encoding = 'utf-8')
target = open(d_path, 'w', encoding = 'utf-8')
wires = []
result = []
inter = re.compile('INT_X')
for line in origin:
l = line.split()
wires.append(l)
for w in wires:
r = []
l = len(w)
counter = l - 3
i = 3
tuple_no = counter/3
r.append(w[0:3])
while i < len(w):
if re.match(inter, w[i]):
r.append(w[i:i+3])
i = i + 3
result.append(r)
for res1 in result:
c = 0
while c < len(res1):
if c != len(res1) - 1:
mid.writelines(str(res1[c]) + ' ')
else:
mid.writelines(str(res1[c]) + '\n')
c = c + 1
'''
for line2 in mid2:
l2 = line2.split("'").split(",")
target.writelines(l2)
'''
#target.writelines(result)
origin.close()
mid.close()
target.close()
'''
for k in result:
writestring = ''
len_k = len(k)
c1 = 0
while c1 < len_k:
for j in k:
len_j = len(k)
c2 = 0
while c2 < len_j:
if c2 != len_j - 1:
writestring = writestring + ' ' + j[c2] + " "
#target.writelines(j[c2] + '')
else:
writestring = writestring + ' ' + j[c2] + "\n"
#target.writelines(j[c2] + '')
c2 = c2 + 1
target.writelines(writestring)
c1 = c1 + 1
'''