Not displaying Input in Python

Question:

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.

Asked By: Python03

||

Answers:

You can use the following library to do so

import getpass

pswd = getpass.getpass('Write your password here:')
print(pswd)
Answered By: Arghya Saha

use getpass

like

import getpass
s = getpass.getpass("Write your password here:")
Write your password here: # input will be hidden

Answered By: nagataaaas

You can use the getpass module in python.

a = getpass.getpass("Write your password here:")

When you do the above you’ll get the following:

Write your password here: #No Characters Shown

You can however write a function to store the entered text and report only a string of *’s when called. Kinda like this, which I did not write

Answered By: Anidh Singh