Search code examples
pythonpython-3.xpasswordspython-3.6

Not displaying Input in Python


I want to ask what changes we can make to our input function so that whatever we type as input is represented as a '*'.As we all have seen that when we type a password on the login page it gets written as ******* .Can this be done in python? something like this:

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)
stackoverflow

The getpass is not working and giving a warning too.


Solution

  • You can use the following library to do so

    import getpass
    
    pswd = getpass.getpass('Write your password here:')
    print(pswd)