A detailed introduction to the getpass module in Pythong

黄舟
Release: 2018-05-16 15:47:17
Original
2235 people have browsed it

I recently stumbled upon this module while reading the official documentation of the Python standard library. After a closer look, the content is quite small. There are only two main APIs. I spent some time reading the source code and found it to be quite practical. I would like to share it with you here. The following article mainly introduces you to the relevant information about the basic getpass module of Python. Friends in need can refer to it.

This article mainly introduces to you the relevant content about the getpass module in Python, and shares it for your reference and study. Without further ado, let’s take a look at the detailed introduction:

getpass module Provides a platform-independent method of entering passwords on the command line;

This module mainly provides:

  • Two functions: getuser, getpass

  • An alarm: GetPassWarning (thrown when the entered password may be displayed. This alarm is a subclass of UserWarning)

Remarks: The above is the alarm thrown when the password is displayed

getpass.getuser()
Copy after login

This function returns the logged in user name. No parameters are required

This function checks the environment variables LOGNAME, USER, LNAME and USERNAME to return a non-empty string. If these variables are set to empty, the username will be obtained from a database that supports passwords, otherwise an exception that the user cannot be found will be triggered!


getpass.getpass([prompt[, stream]])
Copy after login

will display the prompt string, turn off the screen echo of the keyboard, and then read the password

can bring the prompt, Without a prompt, the default prompt 'Password: '

' will be entered. In Linux/Unix systems, the prompt will be written to the class file stream and written to /dev/tty by default. If it cannot be written, it will be written to sys.stderr. If the password is displayed when calling the getpass() function, a GetPassWarning alarm will be thrown, which is read from sys.stdin

Remarks: When the getpass function is adjusted in IDLE, the entered password will be displayed. The password must be displayed in Python Shell or CMD under Windows

[ Example】

Result output:-->


# #Summarize

The above is the detailed content of A detailed introduction to the getpass module in Pythong. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template