for循环后的Python语法错误(在解释器中)

2024-09-21 01:15:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我从控制台运行一些python代码(粘贴在其中),得到了一个意外的结果。代码如下:

parentfound = False
structfound = False
instruct = False
wordlist = []
fileHandle = open('cont.h')
for line in fileHandle:
    if line is "":
        print "skipping blank line"
        continue
    if "}" in line:
        instruct = False
        index = line.index("}")
        wordlist.append(word)
    pass          
try:
    print wordlist
except Exception as e:
    print str(e)

在for循环之后,我想打印wordlist。无论我做什么,我都不能包含for循环之外的任何内容。以下是我收到的错误:

^{pr2}$

不管是我手工把代码输入终端还是粘贴进去,都会发生这种情况。如果您能提供任何帮助,我将不胜感激。谢谢您!在


Tags: 代码infalseforindexif粘贴line

热门问题