我正在从控制台一些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循环。 这是我收到的错误:
... if "}" in line:
... instruct = False
... index = line.index("}")
... wordlist.append(word)
... pass
... try:
File "<stdin>", line 10
try:
^
SyntaxError: invalid syntax
它发生我是否手工输入代码到终端,或者如果我贴上它。我会很感激你能提供任何帮助。 谢谢!