How do I convert a password into asterisks while it is being entered?

前端 未结 9 1975
感情败类
感情败类 2020-11-28 13:31

Is there a way in Python to convert characters as they are being entered by the user to asterisks, like it can be seen on many websites?

For example, if an email use

9条回答
  •  抹茶落季
    2020-11-28 14:03

    You may want to check getpass function.

    Prompt the user for a password without echoing. The user is prompted using the string prompt, which defaults to 'Password: '. On Unix, the prompt is written to the file-like object stream. stream defaults to the controlling terminal (/dev/tty) or if that is unavailable to sys.stderr (this argument is ignored on Windows).

    Note: This module mimics unix password prompts and does not show asterisks.

    Usage:

    import getpass
    getpass.getpass()
    

提交回复
热议问题