删除Python中的最后一个输入行 [英] Delete the last input row in Python

查看:165
本文介绍了删除Python中的最后一个输入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  num = int(raw_input(input number:))
打印\b* 20

控制台输出如

 输入数字:10 



'd喜欢在用户按 ENTER 后删除文本输入数字:10 。退格键 \b 无法做到。

解决方案

这将工作在大多数unix和windows终端...它使用非常简单的ANSI转义。

  num = int(raw_input输入数字:))
print\033 [A \033 [A#ansi escape箭头,然后覆盖行

请注意,在Windows上,您可能需要通过以下方式启用ANSI支持:
http://www.windowsnetworking.com/kbase/windowstips/windows2000/usertips/miscellaneous/commandinterpreteransisupport.html



\033 [A字符串被终端解释为将光标向上移动一行。


I have the following code:

num = int(raw_input("input number: "))
print "\b" * 20

The console output looks like

input number: 10

I'd like to delete the text input number: 10 after the user presses ENTER. The backspace key \b can't do it.

解决方案

This will work in most unix and windows terminals ... it uses very simple ANSI escape.

num = int(raw_input("input number: "))
print "\033[A                             \033[A"    # ansi escape arrow up then overwrite the line

Please note that on Windows you may need to enable the ANSI support using the following http://www.windowsnetworking.com/kbase/windowstips/windows2000/usertips/miscellaneous/commandinterpreteransisupport.html

"\033[A" string is interpreted by terminal as move the cursor one line up.

这篇关于删除Python中的最后一个输入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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