import getpass
[root@localhost ~]# cat test_getpass.py import getpass username = input(“username:”) password = getpass.getpass(“password:”) print(username,password) [root@localhost ~]# python3 test_getpass.py username:jam password: jam hello [root@localhost ~]# C:\Users\Jam>python2 Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit ( AMD64)] on win32 Type “help”, “copyright”, “credits” or “license” for more information. >>> import getpass >>> username = input(“username:”) username:jam Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “<string>”, line 1, in <module> NameError: name ‘jam’ is not defined >>> username = raw_input(“username:”) username:jam >>> password = getpass.getpass(“password:”) password: >>> print(username,password) (‘jam’, ‘hello123’) >>> C:\Users\Jam>python Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AM D64)] on win32 Type “help”, “copyright”, “credits” or “license” for more information. >>> username = input(“username:”) username:jam >>> password = getpass.getpass(“password:”) Traceback (most recent call last): File “<stdin>”, line 1, in <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方法,在linux和windows的python上面可以正常运行
import getpass
username = input(“username:”)
passwrod = getpass.getpass(“password:”)
print(username,passwrod)