读取行时出现Python EOF错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16279564/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:11:50  来源:igfitidea点击:

Python EOF error when reading line

pythoneof

提问by Xiam

I keep getting an EOF error. I don't see any reason it why should be yelling at me. I've tried running it in 3.3 and in 2.7 so I guess there must be something wrong. And although I don't get any errors when i'm in Cloud 9, it won't actually run. And when I use a different IDE, I get that error.

我不断收到 EOF 错误。我看不出有什么理由对我大喊大叫。我试过在 3.3 和 2.7 中运行它,所以我想一定有什么问题。虽然我在Cloud 9 中没有收到任何错误,但它实际上不会运行。当我使用不同的 IDE 时,我会收到该错误。

Executing the code....
$python3 demo.py
Hello! What is your name?Traceback (most recent call last):
  File "demo.py", line 2, in 
    name = input("Hello! What is your name?")
EOFError: EOF when reading a line

Here's my code.

这是我的代码。

import sys
name = input("Hello! What is your name?")
print("So your name is {0}? Cool!".format(name))
age = input("Now tell me how old you are.")
print("So your name is {0} and you're {1} years old?".format(name, age))
yn = input("Y/N?")
if yn == "y":
    print("Okay good!")
elif yn == "n":
    sys.exit(0)

Any help?

有什么帮助吗?

采纳答案by Xiam

I don't know what the problem is, but maybe consider using raw_input?

我不知道问题是什么,但也许可以考虑使用 raw_input?

According to the docs here (http://docs.python.org/2/library/functions.html#input):

根据此处的文档(http://docs.python.org/2/library/functions.html#input):

Consider using the raw_input() function for general input from users.

考虑将 raw_input() 函数用于用户的一般输入。

回答by user2229472

Use raw_inputInstead of input.

使用raw_input代替 input