Python 3: EOF when reading a line (Sublime Text 2 is angry)(Python 3:读取一行时的 EOF(Sublime Text 2 很生气))
问题描述
当真时:回复 = input('输入文本')如果回复 == '停止':休息打印(回复.上())
结果是:<块引用>
输入文本:Traceback(最后一次调用):<module> 中的文件C:PythonProjects5.py",第 2 行回复 = input('输入文本:')EOFError:读取一行时出现EOF[在0.2s内完成,退出代码为1]
它只在 Sublime Text 2 中.我试过 IDLE,试过命令行,一切都很完美.Subleme 为什么要冲我大喊大叫?
顺便说一句,也许你也可以解释一下在这种情况下 EOF 可能意味着什么.当然,我已经阅读了文档,如果从输入中读取 EOF,则会引发相应的错误.我想模拟这种情况.输入仅与键盘有关吗?如果是,我应该输入什么组合键来获得 EOF?
提前谢谢你.
我也遇到了同样的问题.Sublime Text 默认控制台的问题是它不支持输入.
要解决这个问题,你必须安装一个名为 SublimeREPL 的包.SublimeREPL 提供了一个接受输入的 Python 解释器.
有一篇文章解释了详细解决方案.
SublimeREPL 的 GitHub 页面
while True:
reply = input('Enter text')
if reply == 'stop': break
print(reply.upper())
The result was:
Enter text:Traceback (most recent call last): File "C:PythonProjects5.py", line 2, in <module> reply = input('Enter text:') EOFError: EOF when reading a line [Finished in 0.2s with exit code 1]
It is only in Sublime Text 2. I tried IDLE, tried command line, everything is perfect. Why should Subleme shout at me?
By the way, maybe you could also explain my what EOF may mean in such situation. Of course, I have read in the documentation, that if EOF is read from input, the appropriate error is raised. I would like to model this situation. Is input only about the keyboard? If yes, what combination of keys should I input to get EOF?
Thank you in advance.
I had the same problem. The problem with the Sublime Text's default console is that it does not support input.
To solve it, you have to install a package called SublimeREPL. SublimeREPL provides a Python interpreter which accepts input.
There is an article that explains the solution in detail.
GitHub page for SublimeREPL
这篇关于Python 3:读取一行时的 EOF(Sublime Text 2 很生气)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 3:读取一行时的 EOF(Sublime Text 2 很生气)
基础教程推荐
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01