使用 Idle 在 Python 3.3.2 Shell 中实现退格 [英] Implementing a backspace in Python 3.3.2 Shell using Idle

查看:106
本文介绍了使用 Idle 在 Python 3.3.2 Shell 中实现退格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有几个人在寻找 Python 中的退格答案.我搜索过的问题都没有为我回答这个问题,所以这里是:

There are several folks on here looking for backspace answers in Python. None of the questions I have searched have answered this for me, so here goes:

简单目标:能够在一行上打印出一个状态字符串,其中下一个状态覆盖第一个状态.与 % complete 状态类似,我们只是用最新的值覆盖第一行,而不是滚动 1%\n、2% 等的长行.

The Simple Goal: be able to print out a status string on one line, where the next status overwrites the first. Similar to a % complete status, where instead of scrolling a long line of 1%\n, 2%, ... etc. we just overwrite the first line with the newest value.

现在是问题.当我在空闲时输入:print("a\bc") 我得到它作为输出:ac看起来像一个奇怪的盒子,在a"和c"之间有一个圆圈.使用 sys.stdout.write() 时会发生同样的事情.

Now the question. When I type this in idle: print("a\bc") I get this as output: ac with what looks like an odd box with a circle between the 'a' and 'c'. The same thing happens when using sys.stdout.write().

这是空闲编辑器设置/问题吗?有谁知道我在 Idle Shell 中尝试的方法是否可行?

Is this an Idle editor setting/issue? Does anyone even know if what I am trying is possible in the Idle Shell?

感谢您的任何见解.

PS:在 Windows 7、64 位系统上运行 Python 3.3.2 Idle.

PS: Running Python 3.3.2 Idle on Windows 7, 64-bit system.

在 Notepad++ 中复制输出表明 Python 正在打印一个退格"字符,而不是实际返回一个空格.也许我试图完成的事情是不可能的?

Copying the output in Notepad++ is revealing that Python is printing out a 'backspace' character, and not actually going back a space. Perhaps what I am trying to accomplish is not possible?

推荐答案

显然回车 \r 和退格 \b 实际上在 Idle 中不起作用,因为它使用的文本控件不能正确呈现返回/退格.

Apparently the carriage return \r and the backspace \b won't actually work within Idle because it uses a text control that doesn't render return/backspace properly.

您也许可以为 Idle 编写某种补丁,但这可能比它的价值更麻烦(除非您真的喜欢 Idle)

You might be able to write some sort of patch for Idle, but it might be more trouble than it's worth (unless you really like Idle)

这篇关于使用 Idle 在 Python 3.3.2 Shell 中实现退格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆