-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
49 lines (36 loc) · 1.13 KB
/
parse.py
File metadata and controls
49 lines (36 loc) · 1.13 KB
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
#parse.py
#parses the longass list for you
count = 1
res = []
#change your input filename here if you want to call it something else
INPUT_FILE = "input.txt"
#open the file
with open(INPUT_FILE) as f:
content = f.readlines()
#get the name of the gates/input/outputs we care about
gates = content[0].split()
gates = gates[1:len(gates)-1]
print(gates)
LIST_LEN = len(gates)
#delete the first two rows (name + '-----')
content = content[2:]
#if you have an empty row in the end of your file, it'll delete it for you
if content[-1] == '\n':
content = content[:-1]
#parse through the lines
for line in content:
#delimit by spaces
a = line.split()
#get rid of time since we don't use it
a = a[1:]
#create an emtpy string to ouptut
out = ""
#iterate through the gate values in the gate list, and the raw values from the text file
for i in range(0,LIST_LEN):
#build our string
out += gates[i]+ "= " + a[i] + "; "
#on the last line, add an empty line for readability
if i == LIST_LEN-1:
out+='\n'+'#1'
res.append(out)
print(out)