Python 中不显示输入
Not displaying Input in Python
我想问一下我们可以对输入函数进行哪些更改,以便我们输入的任何内容都表示为“*”。正如我们都看到的那样,当我们在登录页面上输入密码时,它会得到写成 ******* 。这可以在 python 中完成吗?
像这样:
Python 3.6.6 (v3.6.6:4cu1f74eh7, Jun 27 2018, 02:47:15) [MSC v.1900 64 bit
(Intel)] on win64
Type "copyright", "credits" or "license()" for more information.
>>> a = input('Write your password here:')
Write your password here: ************* # we write our password
>>> print(a)
Whosebug
The getpass
is not working and giving a warning too.
您可以使用以下库来实现
import getpass
pswd = getpass.getpass('Write your password here:')
print(pswd)
使用getpass
喜欢
import getpass
s = getpass.getpass("Write your password here:")
Write your password here: # input will be hidden
您可以在 python 中使用 getpass 模块。
a = getpass.getpass("Write your password here:")
执行上述操作后,您将获得以下内容:
Write your password here: #No Characters Shown
然而,您可以编写一个函数来存储输入的文本,并在调用时仅报告一串 *。有点像this,不是我写的
我想问一下我们可以对输入函数进行哪些更改,以便我们输入的任何内容都表示为“*”。正如我们都看到的那样,当我们在登录页面上输入密码时,它会得到写成 ******* 。这可以在 python 中完成吗? 像这样:
Python 3.6.6 (v3.6.6:4cu1f74eh7, Jun 27 2018, 02:47:15) [MSC v.1900 64 bit
(Intel)] on win64
Type "copyright", "credits" or "license()" for more information.
>>> a = input('Write your password here:')
Write your password here: ************* # we write our password
>>> print(a)
Whosebug
The getpass
is not working and giving a warning too.
您可以使用以下库来实现
import getpass
pswd = getpass.getpass('Write your password here:')
print(pswd)
使用getpass
喜欢
import getpass
s = getpass.getpass("Write your password here:")
Write your password here: # input will be hidden
您可以在 python 中使用 getpass 模块。
a = getpass.getpass("Write your password here:")
执行上述操作后,您将获得以下内容:
Write your password here: #No Characters Shown
然而,您可以编写一个函数来存储输入的文本,并在调用时仅报告一串 *。有点像this,不是我写的