Python:EOFError:读取一行时的EOF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17758782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: EOFError: EOF when reading a line
提问by Héctor Salazar
This may be repeated, but none of the existing answers solved my problem.
这可能会重复,但现有的答案都没有解决我的问题。
So, I'm using Python 2.7
, and I get this error (title) whenever I try this:
所以,我正在使用Python 2.7
,每当我尝试这样做时,我都会收到此错误(标题):
number = int(raw_input('Number : '))
I tried this in Sublime Text 2, compileronline.com and in codecademy; it fails in the first 2 of this sites. It works on codecademy and in the terminal compiler, but I can't understand exactly why it is failing.
我在 Sublime Text 2、compileronline.com 和 codecademy 中尝试过这个;它在该站点的前 2 个中失败。它适用于 codecademy 和终端编译器,但我不明白为什么它会失败。
采纳答案by jh314
The issue here is that Sublime text 2's console doesn't support input.
这里的问题是 Sublime text 2 的控制台不支持输入。
To fix this issue, you can install a package called SublimeREPL. SublimeREPL provides a Python interpreter that takes in input.
要解决此问题,您可以安装一个名为SublimeREPL的包。SublimeREPL 提供了一个接受输入的 Python 解释器。
And as for compileronline.com, you need to provide input in the "STDIN Input" field on the lower right of the website.
对于 compileronline.com,您需要在网站右下方的“STDIN 输入”字段中提供输入。
回答by Vatsal
try:
value = raw_input()
do_stuff(value) # next line was found
except (EOFError):
break #end of file reached
This seems to be proper usage of raw_input when dealing with the end of the stream of input from piped input. Refer this post
在处理来自管道输入的输入流的末尾时,这似乎是 raw_input 的正确用法。 参考这个帖子