We use getpass() in order to prompt the user for a password without echoing. The module getpass provides for a secure way to handle password prompts where programs interact with users via terminal in python for data science.
The module provides two functions:
- getpass()
The function getpass() is there for prompting the user to use the string prompt and then reads the input from the user in the form of password. The input read defaults to Password and is return to the caller as a string.
Let us see some examples:
Example 1: No prompt is provide by caller
As no prompt is provided by caller, it is set to default prompt “Password”.
Example 2: Security Questions
Several programs are present which ask for security questions instead of asking for passwords to improve security. The prompt can be altered to any value.
- getuser():
getpass.getuser()
The function getuser() displays the login name of user. The function checks for the environment variables LOGNAME, USER, LNAME and USERNAME in this order and then returns the value of first non-empty string.
Example 3:
So, to learn more about getpass function in python for data science, you can check this and this as well.