删除用户输入Python

时间:2015-11-22 10:58:33

标签: python input delete-row sys

如果我有这样一个简单的代码:

while 1:
    text = raw_input()
    print 'You have written "%s" text'% (text)

如果我启动程序并写“hello”,则输出为:

hello
You have written "hello" text

第一个“你好”是我的输入(使用raw_input但我也可以使用sys.stdin.readline)

我如何删除第一个“你好”(我的输入)才能输出如下:

You have written "hello" text

1 个答案:

答案 0 :(得分:2)

您可以在打印所需行之前清除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)