删除Python中的最后一条STDOUT行 [英] remove last STDOUT line in Python
本文介绍了删除Python中的最后一条STDOUT行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何禁止在标准输出上显示用户输入。
I am trying to figure out how to suppress the display of user input on stdout.
raw_input()
后跟任何打印语句将保留用户键入的内容。 getpass()
不显示用户键入的内容,但会保留 Password:提示。
raw_input()
followed by any print statement preserves what the user typed in. getpass()
does not show what the user typed, but it does preserve the "Password:" prompt.
要解决此问题,我只想删除最后一行(这也会从行尾删除换行符)。
To fix this, I would like to only remove the last line (which would remove the newline from the end of the line as well).
推荐答案
您也许可以使用 VT100控制代码。
类似这样的东西:
CURSOR_UP_ONE = '\x1b[1A'
ERASE_LINE = '\x1b[2K'
print(CURSOR_UP_ONE + ERASE_LINE)
这篇关于删除Python中的最后一条STDOUT行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文