【发布时间】:2016-06-06 05:30:16
【问题描述】:
我正在用 Python 编写一个简单的代码并收到此错误: 回溯(最近一次通话最后): 文件“prog.py”,第 4 行,在 EOFError:读取一行时出现EOF
我的代码是:
inp = [""]
i=0
while i==0:
answer = raw_input("")
if answer!="":
inp.append(answer)
else:
break
for item in inp:
if item=="42":
break
else:
print item
print ""
【问题讨论】:
-
您何时收到此错误?我可以用
python2 prog.py < /dev/null生成它...当我输入文本和/或空行时,它会像猜测的那样工作(通过阅读代码)。您想屏蔽 EOFError 还是想了解它发生的原因? -
你是如何运行你的脚本的? quite many answers regarding this 已经在这里了,所以也许你应该先阅读其中的一些。
-
我的代码在 Codeacdemy.com 编译器上也运行良好,但在 Ideone.com 上,它给出了这个错误
标签: python python-2.7 eof