有没有一种方法可以在不使用\ b的情况下打印出python的backpace?
我想发挥打字效果,但我无法打印回头台。我尝试使用print('\ b')
,但它只是打印出一个X-ed Out Square。还有其他打印靠背的方法吗?如果有助于我将MU用作我的代码编辑器。
I want to make a typing effect but I can't print a backspace. I tried using print('\b')
but it just printed out an x-ed out square. Are there any other ways to print a backspace? If it helps I'm using Mu as my code editor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是在您的IDE中运行脚本,其终端(显然)不支持擦除字符(在此并不罕见;使用Python发货的闲置IDE也不支持输出中的背景)。在常规终端(例如
cmd.exe
)在Windows上运行,bash
或标准 *nix终端上的like)和打印'\ b'<
'\ b'< /代码>工作。这全都取决于终端如何支持(或不支持)backpacing。
为了记录,您要使用:
或:
避免尾随的新线(在角色上进行backpace不应将您迫使您作为副作用的下一行)。
The problem is running the script in your IDE, whose terminal (apparently) doesn't support backspacing to erase characters (it's not unusual in this; the IDLE IDE that ships with Python doesn't support backspaces in output either). Run it in a regular terminal (e.g.
cmd.exe
on Windows,bash
or the like on a standard *NIX terminal), and printing'\b'
works. It's all up to the terminal how it supports (or doesn't support) backspacing.For the record, you'd want to use either:
or:
to avoid the trailing newline (backspacing over a character shouldn't force you to the next line as a side-effect).