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

myt*_*889 3 python syntax file syntax-error

我正在从控制台运行一些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)
Run Code Online (Sandbox Code Playgroud)

在for循环之后,我想打印出来wordlist.无论我做什么,我都不能在for循环之外包含任何东西.这是我收到的错误:

...     if "}" in line:
...         instruct = False
...         index = line.index("}")
...         wordlist.append(word)
...     pass          
... try:
  File "<stdin>", line 10
    try:
      ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

无论我是手动将代码输入终端还是粘贴它,都会发生这种情况.我很感激您提供的任何帮助.谢谢!

Ign*_*ams 9

...REPL中的提示表示它仍未完成上一个块.您需要按Enter空行才能首先终止它.