-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathICO.py
70 lines (68 loc) · 1.46 KB
/
ICO.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
import ast
import copy
filein=open('icg.txt','r')
fileout=open('oic.txt','w')
a=filein.readlines()
update_table={}
result=''
b=[i for i in a if i!='\n']
for i in b:
if '=' in i and '<' not in i and '>' not in i and '==' not in i: #only assignment
k=copy.deepcopy(i)
k=k.split('=')
try:
k[0]=k[0].replace(" ",'')
a=int(k[1])
if k[0] in update_table.keys():
update_table[k[0]]=a
else:
update_table[k[0]]=a
except:
update_table[k[0]]=None
temp=copy.deepcopy(i)
temp=temp.split(' ')
for j in update_table.keys():
for k in range(len(temp)):
if j == temp[k] and update_table[j]!=None:
temp[k]=update_table[j]
for j in temp:
if j != '\n':
result+=str(j) + ' '
else:
result+='\n'
break
else:
temp=copy.deepcopy(i)
temp=temp.split(' ')
for j in update_table.keys():
for k in range(len(temp)):
if j == temp[k] and update_table[j]!=None:
temp[k]=update_table[j]
for j in temp:
if j != '\n':
result+=str(j) + ' '
else:
result+='\n'
break
#result+=i
import io
result=io.StringIO(result)
b=result.readlines()
result=''
for i in b:
if '=' in i and '<' not in i and '>' not in i and '==' not in i: #only assignment
k=copy.deepcopy(i)
k=k.split('=')
try:
k[1]=k[1].replace(" ",'')
#print(k[1])
k[1]=ast.literal_eval(k[1])
k=k[0] + ' = ' + str(k[1])
except:
k=k[0] + ' = ' + k[1]
result+=k+'\n'
else:
result+=i
#print(b)
fileout.write(result)
#print(b)