码迷,mamicode.com
首页 > 编程语言 > 详细

Python之路【第一篇】:Python基础(3)

时间:2016-05-14 06:43:46      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

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)
 

Python之路【第一篇】:Python基础(3)

标签:

原文地址:http://www.cnblogs.com/jiangnanmu/p/5491791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!