use getpass in visual studio code

Question:

I am using this code:

import getpass

pwd = getpass.getpass(prompt = 'Please enter password:')

Unfortunatley I cannot enter anything in the terminal. Am I missing something?

Asked By: cs0815

||

Answers:

The principle of this function is that you can enter text as in a classic input but it is not displayed on the screen.
If you try to add print(pwd) and hit some keys at the time of input, it should return exactly what you typed

Answered By: crazycat256

I was trying to figure this out myself, and realised that in VS Code the prompt to enter the password appears at the top of the window, not inline as it does in Jupyter.

I found this a bit confusing coming from a Jupyter environment, so added some code to check if the user was running VS Code and display an additional message:

if any(['VSCODE' in x for x in os.environ.keys()]):
   print('Please enter password in the prompt above')
Answered By: galexioza
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.