python - 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
谢谢你的支持
解决方案
您的测试可能以非交互方式运行代码。如果您在 Python 中创建测试,请尝试使用 subprocess.PIPE 以便您可以与子流程进行通信。如果没有有效的标准输入,程序将抛出此错误,这(应该)导致您的测试失败。
推荐阅读
- javascript - 通用 Firestore 方法
- mongodb - $lookup get "first" 并结合 addField + exclude 字段
- javascript - 如何通过沙盒参数在 iframe 上允许跨域
- google-ads-script - 用于在附加链接过期时删除的 Google Ads 脚本
- python - 如何将参数传递给python中的嵌套类
- r - 如何使用任意一组标准对数据进行子集化或过滤?
- php - 如何使用 Guzzle 发布包含文件字段的 json 数据?
- stripe-payments - 我想在 symfony 应用程序中使用 Stripe Prebuilt Checkout Page 构建一个简单的结帐页面
- redis - Redis 订阅频道(应该启用键空间通知??)
- python - 使用 Python 的网络扫描仪