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 pwddudiaohanjiangxue getpass模块提供了两个函数。 getpass.getpass([prompt[, stream]]):提示用户输入密码。用户输入的内容并不会在屏幕上显示出来。###########getpass.getuser():获得登陆的用户名>>> user = getpass.getuser()>>> print userroot#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")root0>>> os.system("echo $USER")root0>>> os.system("echo $LNAME")0Python 的详细介绍:请点这里 Python 的下载地址:请点这里推荐阅读:《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm