简体   繁体   English

EOFError:读取一行时出现EOF,不知道为什么

[英]EOFError: EOF when reading a line, can't figure out why

I've been trying to make a python Among Us game (kinda I guess) but this error has been really annoying.我一直在尝试在我们中间制作 python 游戏(我猜有点),但这个错误真的很烦人。 Here is my code:这是我的代码:

import random
print("Python Among Us")
print()
role = ["Crewmate", "Crewmate" , "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Impostor"]
roleconfirmed = random.choice(role)
print("You are a", roleconfirmed, "!")
if roleconfirmed == ("Crewmate"):
    firstdestination = input("Where would you like to go? ")

Here is the exact error in the console:这是控制台中的确切错误:

Python Among Us

You are a Crewmate !
Where would you like to go? Traceback (most recent call last):
  File "main.py", line 8, in <module>
    firstdestination = input("Where would you like to go? ")
EOFError: EOF when reading a line

Any ideas why this error still persists?任何想法为什么这个错误仍然存在?

I think you are using an online IDE, or giving an empty input file to read input from.我认为您正在使用在线 IDE,或者提供一个空输入文件来读取输入。

I was able to re-generate your exception, when i created an empty file empty.txt and passed that as argument while running above code segment.当我创建一个空文件empty.txt并将其作为参数在上面的代码段运行时,我能够重新生成您的异常。

$ python3 main.py < empty.txt
Python Among Us

You are a Crewmate !
Where would you like to go? Traceback (most recent call last):
  File "/Users/vishvanath/Desktop/test/main.py", line 8, in <module>
    firstdestination = input("Where would you like to go? ")
EOFError: EOF when reading a line

Here, main.py contains code segment provided in question and empty.txt is just an empty file.在这里, main.py包含有问题的代码段,而empty.txt只是一个空文件。

So error occurs, because your program is expecting an input, but there is none.所以会发生错误,因为您的程序需要输入,但没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM