我不断收到SyntaxError,但我不知道为什么

时间:2020-08-01 22:18:35

标签: python syntax

这是我的代码:

29 for i, j in enumerate(self.noun):
30      if j in self.c:
31          try:
32              k = j + self.noun[i + 1]
33              if k in c:
34                  self.letters.append(k)
35                  if k in self.unp:
36                      self.letstat.append("CN")
37                  elif k in self.pr:
38                      self.letstat.append("CP")
39                  else:
40                      self.letstat.append("CA")
41                      
42          self.letters.append(j)
43          if j in self.unp:
44              self.letstat.append("CN")
45          elif j in self.pr:
46              self.letstat.append("CP")
47          else:
48              self.letstat.append("CA")
49      else:
50          try:
51              if j == "i" and self.noun[i - 1] in self.pr:
52                  continue
53          self.letters.append(j)
54          self.letstat.append("V")

我不断收到此错误:

Traceback (most recent call last):                                                                                        
File "C:\Users\User\Documents\programming\Python\yisib\main.py", line 1, in <module>                                      
from nouns import Noundec                                                                                             
File "C:\Users\User\Documents\programming\Python\yisib\nouns.py", line 42                                                 
self.letters.append(j)                                                                                                  
^                                                                                                                   
SyntaxError: invalid syntax

有人可以告诉我我做错了什么吗?我已经检查了7次代码,而且似乎没有遗漏任何括号或缩进。谢谢

1 个答案:

答案 0 :(得分:1)

使用except时需要finallytry

try:
    if j == "i" and self.noun[i - 1] in self.pr:
        continue
except IndexError:
    pass

self.letters.append(j)

问题是:为什么?您是否期望IndexError吗?