从标准输入读取密码 [英] Read password from stdin
本文介绍了从标准输入读取密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
场景:交互式CLI Python程序,需要密码.这也意味着,不可能有GUI解决方案.
Scenario: An interactive CLI Python program, that is in need for a password. That means also, there's no GUI solution possible.
在bash中,无需重新输入密码就可以读取密码
In bash I could get a password read in without re-prompting it on screen via
read -s
Python是否有类似的东西?即
Is there something similar for Python? I.e.,
password = raw_input('Password: ', dont_print_statement_back_to_screen)
替代方法:将键入的字符替换为'*',然后再将其发送回屏幕(又称浏览器样式).
Alternative: Replace the typed characters with '*' before sending them back to screen (aka browser' style).
推荐答案
>>> import getpass
>>> pw = getpass.getpass()
这篇关于从标准输入读取密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文