Python 删除输入行
Python deleting input line
我想在 python 3 中有一个输入循环,其中输入的信息会自动从终端中删除(f.eks。3 秒后)
我知道用 \r 返回队列的功能,但在输入后与自动换行斗争。
while True:
inputStr = (input("Add the hidden word: ")).lower()
processingTheInput(inputStr) #some sort of function using the input word
您想用函数清除终端
# import only system from os
from os import system, name
# import sleep to show output for some time period
from time import sleep
# define our clear function
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
现在你需要一个函数,将你的单词添加到列表中,然后运行清除函数,最后可以在最后选择一个单词
Ansi 转义码在所有终端上的工作方式不同,但这可能适合您的需要。 ‘\033’ 是转义符。 '[1A' 表示向上一行,'[K' 表示擦除到这一行的末尾。
prompt = 'Add the hidden word: '
inputStr = input(prompt).lower()
print ('3[1A' + prompt + '3[K')
我想在 python 3 中有一个输入循环,其中输入的信息会自动从终端中删除(f.eks。3 秒后) 我知道用 \r 返回队列的功能,但在输入后与自动换行斗争。
while True:
inputStr = (input("Add the hidden word: ")).lower()
processingTheInput(inputStr) #some sort of function using the input word
您想用函数清除终端
# import only system from os
from os import system, name
# import sleep to show output for some time period
from time import sleep
# define our clear function
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
现在你需要一个函数,将你的单词添加到列表中,然后运行清除函数,最后可以在最后选择一个单词
Ansi 转义码在所有终端上的工作方式不同,但这可能适合您的需要。 ‘\033’ 是转义符。 '[1A' 表示向上一行,'[K' 表示擦除到这一行的末尾。
prompt = 'Add the hidden word: '
inputStr = input(prompt).lower()
print ('3[1A' + prompt + '3[K')