Python 3:读取一行时的 EOF(Sublime Text 2 很生气)

2024-04-21Python开发问题
1

本文介绍了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 很生气)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11