python - 删除用户输入的Python

标签 python input delete-row sys

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

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/

相关文章:

python - 通过 AdminSite.get_urls 添加非基于模型的 URL 不起作用

python - Tensorflow:_variable_with_weight_decay(...) 解释

python - 使用多个 DateTimeIndex 分解数据框的最有效方法

assembly - 使用 ARM 汇编语言获取用户输入

MySQL 使用子查询删除行

android - whereArgs SQLite 数据库删除

python - 以相反顺序迭代 2 个不同长度的列表

python - 如何使用 Python 的计时器一次读取一个字符的键盘输入

c# - Console.Read() 和 Console.ReadLine() 之间的区别?

MySQL 查询删除时间戳早于当前时间戳的行