Import Getpass[[email protected] ~]# cat Test_getpass.pyimport getpassusername = input ("username:") password = Getpass.getpass ("Password:") print (Username,password) [[email protected] ~]# Python3 Test_getpass.pyusername:jam Password:jam Hello[[email protected] ~]# C:\users\jam>python2python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5, 20:40:30) [MSC v.1500-bit (AMD64)] on Win32typ E "Help", "copyright", "credits" or "license" for more information.>>> import getpass>>> username = Inpu T ("username:") username:jamtraceback (most recent call last): File "<stdin>", line 1, in <module> file "<s Tring> ", line 1, in <module>nameerror:name ' jam ' isn't defined>>> username = raw_input (" username: ") use rname:jam>>> Password = getpass.getpass ("Password:") password:>>> print (Username,password) (' Jam ', ' hello123 ') >>> C:\users\jam>pythonpython 3.5.1 (v3.5.1:37a07cee5969, Dec 6, 01:54:25) [MSC v.1900-bit (AMD64)] on Win32type " Help "," copyright "," credits "or" license "for more information.>>> username = input (" username: ") username:jam& gt;>> Password = getpass.getpass ("Password:") Traceback (most recent call last): File ' <stdin> ', line 1, in &L T;module>nameerror:name ' Getpass ' is not defined>>> import getpass>>> username = input ("Username:" ) username:jam>>> password = getpass.getpass ("Password:") password:>>> print (Username,password) jam Hello123>>> #!/usr/bin/env python
#-*-Coding:utf-8-*-
#pycharm里面无法使用getpass方法, it works on Linux and Windows Python
Import Getpass
Username = input ("username:")
Passwrod = Getpass.getpass ("Password:") print (Username,passwrod)
Python's Way "first": Python Basics (3)