I’m having this error:
JavaScript
x
5
1
File "zzz.py", line 70
2
else:
3
^
4
SyntaxError: invalid syntax
5
The line which causes the problem is marked with a comment in the code:
JavaScript
1
41
41
1
def FileParse(self, table_file):
2
vars={}
3
tf = open(table_file, 'r')
4
for line in tf:
5
if line.startswith("#") or line.strip() == "": pass
6
elif line.startswith("n_states:"):
7
self.n_states = str(line[9:].strip())
8
elif line.startswith("neighborhood:"):
9
self.neighborhood = str(line[13:].strip())
10
elif line.startswith("symmetries:"):
11
self.symmetries = str(line[11:].strip())
12
elif line.startswith("var "):
13
line = line[4:]
14
ent = line.replace('=',' ').
15
replace('{',' ').
16
replace(',',' ').
17
replace(':',' ').
18
replace('}',' ').
19
replace('n','').split()
20
vars[ent[0]] = []
21
for e in ent[1:]:
22
if e in vars: vars[ent[0]] += vars[e]
23
else:
24
vars[ent[0].append(int(e))]
25
else:
26
rule = line.strip().split(",")
27
for k in vars.keys():
28
if k in rule:
29
for i in vars[k]:
30
change = rule.replace(k, i)
31
change = [int(x) for x in change]
32
w.rules.append(Rule(change[:5],change[5])
33
34
else: # line which causes the problem
35
36
rule = [int(x) for x in rule]
37
w.rules.append(Rule(rule[:5],rule[5]))
38
tf.close()
39
self.parse_status "OK"
40
return w.rules
41
w.rules
is variable which is assigned to “World” class.
To be honest I have no idea why I get this. Before everything was fine and now that error shows up after adding some extra instructions in other indented blocks.
Any ideas?
Advertisement
Answer
Because you left out a closing brace
JavaScript
1
2
1
w.rules.append(Rule(change[:5],change[5]) )
2