gpt4 book ai didi

python - 解析时出现意外的 EOF

转载 作者:行者123 更新时间:2023-12-01 06:12:09 25 4
gpt4 key购买 nike

while True:
no=input()
if no=='':
break
else:
split_change(no)

这会产生 EOF 错误,如何在从 std 输入获取输入时检查 EOF ?

最佳答案

这个怎么样:

  while True:
try:
no=raw_input()
if no=='':
break
else:
split_change(no)
except EOFError:
break

编辑:将 input() 更改为 raw_input(),并意识到您必须使用 try/except 否则您仍然会收到错误。

EDIT2:将 1 更改为 True

关于python - 解析时出现意外的 EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5217258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com