设为首页 加入收藏

TOP

Python 之getpass模块
2014-11-24 00:08:14 来源: 作者: 【 】 浏览:6
Tags:Python getpass 模块

Python 之getpass模块


getpass.getpass([prompt[, stream]]):


prompt:为用户输入的提示字符串,默认为:Password:


>>> pwd = getpass.getpass()


Password:


>>> print pwd



>>> pwd = getpass.getpass(prompt='please input your password: ')


please input your password:


>>> print pwd


dudiaohanjiangxue



getpass模块提供了两个函数。



getpass.getpass([prompt[, stream]]):提示用户输入密码。用户输入的内容并不会在屏幕上显示出来。


###########


getpass.getuser():获得登陆的用户名


>>> user = getpass.getuser()


>>> print user


root


#This function checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an exception is raised


#这个函数会按顺序检查环境变量:LOGNAME,USER,LNAME,USERNAME


>>> import os


>>> os.system('echo $LOGNAME')


root


0


>>> os.system('echo $USER')


root


0


>>> os.system('echo $LNAME')


0


推荐阅读:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python 之 paramiko 模块 下一篇Python 之连接MySQL模块-MySQLdb

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: