如果我有一个像这样的简单代码:
while 1:
text = raw_input()
print 'You have written "%s" text'% (text)
如果我启动程序并写“hello”,输出为:
hello
You have written "hello" text
第一个“hello”是我的输入(使用 raw_input 获取,但我也可以使用 sys.stdin.readline)
如何删除第一个“hello”(我的输入)以获得如下输出:
You have written "hello" text
最佳答案
您可以在打印所需的行之前清除 CLI。
import os
os.system('clear')
如果是Unix系统。在 Windows 上是 cls
。
编辑: 如果您需要将其用于聊天客户端,您可以将用户输入保存在列表中并清除 cli 并打印用户输入列表
userInputs = []
...
text = raw_input ()
userInputs.append (text)
os.system ('clear')
for i in userInputs:
print (i)
关于python - 删除用户输入的Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33854013/