pythonelse语法错误_为什么“else”⾏给出⽆效语法错误?我犯了个错误:File "zzz.py", line 70
else:
^
SyntaxError: invalid syntax
导致问题的⾏在代码中⽤注释标记:def FileParse(self, table_file):
vars={}
tf = open(table_file, 'r')
for line in tf:
if line.startswith("#") or line.strip() == "": pass
elif line.startswith("n_states:"):
self.n_states = str(line[9:].strip())
elif line.startswith("neighborhood:"):
error ighborhood = str(line[13:].strip())
elif line.startswith("symmetries:"):
self.symmetries = str(line[11:].strip())
elif line.startswith("var "):
line = line[4:]
ent = place('=',' ').\
replace('{',' ').\
replace(',',' ').\
replace(':',' ').\
replace('}',' ').\
replace('\n','').split()
vars[ent[0]] = []
for e in ent[1:]:
if e in vars: vars[ent[0]] += vars[e]
else:
vars[ent[0].append(int(e))]
else:
rule = line.strip().split(",")
for k in vars.keys():
if k in rule:
for i in vars[k]:
change = place(k, i)
change = [int(x) for x in change]
w.rules.append(Rule(change[:5],change[5])
else: # line which causes the problem
rule = [int(x) for x in rule]
w.rules.append(Rule(rule[:5],rule[5]))
tf.close()
self.parse_status "OK"
return w.rules
w.rules是分配给“World”类的变量。
⽼实说,我不知道我为什么会得到这个。以前⼀切都很好,现在在其他缩进的块中添加⼀些额外的指令之后,这个错误就出现了。有什么想法吗?
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论