python else语法错误_为什么“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:"):

self.neighborhood = str(line[13:].strip())

elif line.startswith("symmetries:"):

self.symmetries = str(line[11:].strip())

elif line.startswith("var "):

line = line[4:]

ent = line.replace('=',' ').\

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 = rule.replace(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”类的变量。

老实说,我不知道我为什么会得到这个。以前一切都很好,现在在其他缩进的块中添加一些额外的指令之后,这个错误就出现了。

有什么想法吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值