从stdin读取密码(Read password from stdin)
场景:交互式CLI Python程序,需要一个密码。 这也意味着没有GUI解决方案可能。
在bash中,我可以在屏幕上重新提示密码读取密码
read -sPython有什么类似的东西吗? 也就是说,
password = raw_input('Password: ', dont_print_statement_back_to_screen)替代方法:使用'*'替换输入的字符,然后再发送回屏幕(又称浏览器样式)。
Scenario: An interactive CLI Python program, that is in need for a password. That means also, there's no GUI solution possible.
In bash I could get a password read in without re-prompting it on screen via
read -sIs 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() >>> import getpass >>> pw = getpass.getpass()更多推荐
发布评论