Python-是否清除用户输入?

问题描述 投票:2回答:2

我是python的新手,正在使用3.3.3版本。

假设我们有此脚本:

name = "user"
say = input("Say: ")
print (name, "said:",say)

如果我运行它,输出将是:

Say: mytext
user said: mytext

我想知道,有没有办法清除/删除“说:我的文字”?只是为了使其更加清晰:

I want:
    user said: hi
    user said: test
    user said: ..

I don't want:
    Say: hi
    user said: hi
    Say: test
    user said: test

就这样,提前thnx:)

python input echo
2个回答
0
投票

您不能简单地告诉input功能隐藏用户输入。但是您可以使用getpass函数,该函数将完全相同:


1
投票
name = "user"
say = input("Say: ")
sys.stdout.write("\033[F")
print (name, "said:", say)
© www.soinside.com 2019 - 2024. All rights reserved.