首页 > 解决方案 > EOFError:读取一行时出现 EOF - 在井字游戏中 - Python

问题描述

在测试期间它显示错误消息:


   Traceback (most recent call last):
     File "tictactoe/tictactoe.py", line 10, in <module>
       coordinates = input("Enter the coordinates: ")
   EOFError: EOF when reading a line

我无法想象是什么导致了这个问题。代码是:

c = True
while c:
  coordinates = input("Enter the coordinates: ")  # <-- line 10 is this one
  if coordinates == '':
    print("Coordinates should be from 1 to 3!")
    continue
  elif len(coordinates) < 3 or len(coordinates) > 3:
    print("Coordinates should be from 1 to 3!")
    continue

谢谢你的支持

标签: pythoneoferror

解决方案


您的测试可能以非交互方式运行代码。如果您在 Python 中创建测试,请尝试使用 subprocess.PIPE 以便您可以与子流程进行通信。如果没有有效的标准输入,程序将抛出此错误,这(应该)导致您的测试失败。


推荐阅读