python开发_getpass_获取登录名
我们有时候需要获取到计算机的登录名,这时候,就可以使用python中的getpass模块了
下面是我做的demo
运行效果:

==================================================
代码部分:
==================================================
#python getpass #Author : Hongten
#Mailto : hongtenzone@foxmail.com
#Blog : http://www.cnblogs.com/hongten
#QQ : 648719819
#Version : 1.0 import getpass '''
The getpass module provides two functions: getpass.getpass(prompt = 'Password:', stream = None)
Prompt the user form a password without echoing.
The user is prompted using the string prompt,which
defaults to 'Password:' .On Unix, the prompt is written
to the file-like object stream.stream defaults to the
controlling terminal(/dev/tty) or if that is unavailable
to sys.stderr(this argument is ignoed on Windows) if echo free input is unavailable getpass() falls back to
printing a warning message to stream and reading from
sys.stdin and issuing a GetPassWarning. Availablity:Macintosh,Unix,Windows. Note:
if you call getpass from within IDLE,the input may be done in
the terminal you launched IDLE from rather than the idle window
itself. exception getpass.GetPassWarning
A UserWarning subclass isssued when password input may be echoed. getpass.getuser()
Return the 'login name' of the user.Availavility:Unix,Windows. This function checks the environment variables LOGNAME, USER,LNAME and
USERNAME,in order, and returns the values 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. '''
def get_system_user_name():
'''return the 'login name' of the user.'''
return getpass.getuser() def main():
user_name = get_system_user_name()
print('the system user\'s name is : [{}]'.format(user_name)) if __name__ == '__main__':
main()
python开发_getpass_获取登录名的更多相关文章
- python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_获取单选菜单值
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发 getpass获取操作系统登陆名
需用使用python getpass模块 import getpass def get_system_user_name(): return getpass.getuser() def main(): ...
- python开发_platform_获取操作系统详细信息工具
''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...
- 用户管理的设计--4.jquery的ajax实现登录名的校验
页面效果 鼠标失去焦点时,不需要刷新页面进行校验,判断登录名是否重复. 实现步骤 1.引入struts2-json-plugin-2.5.10.1插件包 2.页面使用jquery的ajax实现后台校验 ...
- Python开发实战教程(8)-向网页提交获取数据
来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...
- 测试开发Python培训:模拟登录新浪微博-技术篇
测试开发Python培训:模拟登录新浪微博-技术篇 一般一个初学者项目的起点就是登陆功能的自动化,而面临的项目不同实现的技术难度是不一样的,poptest在做测试开发培训中更加关注技术难点,掌握技 ...
- python获取函数名
Date: 20140223Auth: Jin 参考: http://hi.baidu.com/greysign/item/d11919d325c4c2e6b2f777bf 获取函数名python中获 ...
- //可以不保存在session中, 并且前面我保存在request,这里session也可以获取 chain.doFilter(request, response); //只有登录名不为空时放行,防止直接登录 成功的页面
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...
随机推荐
- Python基础(1):dir(),help()
Python:3.6.4 开始编写Python程序了...可是,某个模块怎么用呢?模块里的函数怎么用呢?...使用本文介绍的dir().help()两个帮助函数可以 获得绝大部分开发所需要的信息! d ...
- 【h5标签转小程序标签】小程序使用wxParse解析html教程
一.先下载所需文件,下载地址:https://pan.baidu.com/s/1umZO9uI24zUTRd7VqaWbAg ,下载完毕后会得到一个wxParse文件夹,后面会用到: 二.先拷贝cs ...
- java基础80 JSP基础知识点(网页知识)
1.jsp的引入 Servlet的作用:用java语言开发动态资源技术!!! Jsp的作用:用java语言(+html语言)开发的动态资源技术!!! Jsp就是servlet 问题:为什 ...
- wpf设置某容器透明,而不应用到容器的子元素的方法
以Border打比方: <Border.Background> <SolidColorBrush Opacity="0.4" Color="Black& ...
- 以太坊go-ethereum常见问题汇总
(1)什么是 Ethereum? 以太坊是一个分散的智能合同平台,由Ether的加密货币提供支持. (2) 听说过以太坊,但什么是Geth,Mist,Ethminer,Mix? Geth: 以太坊节点 ...
- hdu 1007 N个点中输出2点的最小距离的一半
分治法 Sample Input20 01 121 11 13-1.5 00 00 1.50 Sample Output0.710.000.75 # include <iostream> ...
- Hive SQL综合案例
一 Hive SQL练习之影评案例 案例说明 现有如此三份数据:1.users.dat 数据格式为: 2::M::56::16::70072, 共有6040条数据对应字段为:UserID BigInt ...
- 【LOJ】 #2033. 「SDOI2016」生成魔咒
题解 就是字符集较大需要离散化和建边表的后缀自动机水题 每次会加入i个新的串,其中重复的就是i的父亲节点所在节点的长度,减掉即可 代码 #include <iostream> #inclu ...
- 【洛谷】P2000 拯救世界
题解 小迪的blog : https://www.cnblogs.com/RabbitHu/p/9178645.html 请大家点推荐并在sigongzi的评论下面点支持谢谢! 掌握了小迪生成函数的有 ...
- CentOS7.5安装cairo-dock,比mac托盘还美
1.下载安装nux-desktop 到http://li.nux.ro/download/nux/dextop/el7/x86_64/找到nux-dextop-release-xxxx.nux.noa ...