pythongetpass_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 的详细介绍

:请点这里

Python 的下载地址

:请点这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值