getpass() and getuser() in Python:

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:

  1. 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

getpass() and getuser() in Python for Data Science - PST Analytics

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.

  1. 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:

getpass() and getuser() in Python for Data Science - PST Analytics

So, to learn more about getpass function in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.