Python删除输入行 [英] Python deleting input line

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

问题描述

我想在 python 3 中有一个输入循环,其中输入的信息会自动从终端中删除(3 秒后)我知道带有 \r 的函数可以返回到队列中,但是在输入后会自动换行.

I would like to have an input loop in python 3 where the information which gets typed in gets deleted from terminal automatically (f.eks. after 3 seconds) I know the function with \r to go back in line, but struggle with the automatic new line after input.

while True:
    inputStr = (input("Add the hidden word: ")).lower()
    processingTheInput(inputStr) #some sort of function using the input word

推荐答案

Ansi 转义码在所有终端上的工作方式不同,但这可能适合您的需求.‘\033’是转义字符.[1A"表示向上一行,[K"表示擦除到这一行的末尾.

Ansi escape codes will not work the same on all terminals but this might suit your needs. The ‘\033’ is the escape character. The ‘[1A’ says go up one line and the ‘[K’ says erase to the end of this line.

prompt = 'Add the hidden word: '
inputStr = input(prompt).lower()
print ('\033[1A' + prompt + '\033[K')

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

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