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 ...
随机推荐
- nginx自定义500,502,504错误页面无法跳转【转】
1.自定一个页面,这个页面是一个链接地址可以直接访问的. 以下是nginx的配置: location / { proxy_pass http://tomcat_app108; ...
- c++语言知识点汇总
c++ primer version-5 的整理 section 1: 内置类型和自定义类型: main函数的返回值:指示状态.0:成功:1:系统定义. unix和win系统中,执行完程序可以使用ec ...
- weblogic更改端口
两种方式: 1.访问console控制台页面,进入“环境\服务器\需要修改端口的服务器如AdminServer”,修改监听端口,保存并激活更改即可: 2.修改配置文件,进入weblogic的域目录,如 ...
- 网络协议之TCP
前言 近年来,随着信息技术的不断发展,各行各业也掀起了信息化浪潮,为了留住用户和吸引用户,各个企业力求为用户提供更好的信息服务,这也导致WEB性能优化成为了一个热点.据分析,网站速度越快,用户的黏性. ...
- JAVA 解析TXT文本
package file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...
- peda的官方文档说明
peda在github上的官方文档,摘抄过来,方便查阅. 安装 git clone https://github.com/longld/peda.git ~/peda echo "sourc ...
- element-ui 2.7.2版本使用 表格展开行 功能遇到的奇葩问题?
在使用 element-ui 2.7.2版本的时候报下面的错误: [Vue warn]: Error in callback for watcher "data": "E ...
- PHP性能调优,PHP慢日志---善用php-fpm的慢执行日志slow log,分析php性能问题
众所周知,MySQL有slow query log,根据慢查询日志,我们可以知道那些sql语句有性能问题.作为mysql的好搭档,php也有这样的功能.如果你使用php-fpm来管理php的话,你可以 ...
- .net/c#常用框架/中间件简介
任务调度 Quartz.NET:Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等. Quartz.NET允 许开发人员根据时间间隔 ...
- 关于ARM指令那些你必须知道的东西
1.32位ARM指令每一位都有其作用,具体如下: 低12为第二操作数, 12~15位为目的寄存器, 16~19位为第一操作数, 20~27就是操作码, 28~31就是条件域. 2.多寄存器load和s ...