我们有时候需要获取到计算机的登录名,这时候,就可以使用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_获取登录名的更多相关文章

  1. python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  2. python开发_tkinter_获取单选菜单值

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  3. python开发 getpass获取操作系统登陆名

    需用使用python getpass模块 import getpass def get_system_user_name(): return getpass.getuser() def main(): ...

  4. python开发_platform_获取操作系统详细信息工具

    ''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...

  5. 用户管理的设计--4.jquery的ajax实现登录名的校验

    页面效果 鼠标失去焦点时,不需要刷新页面进行校验,判断登录名是否重复. 实现步骤 1.引入struts2-json-plugin-2.5.10.1插件包 2.页面使用jquery的ajax实现后台校验 ...

  6. Python开发实战教程(8)-向网页提交获取数据

    来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...

  7. 测试开发Python培训:模拟登录新浪微博-技术篇

    测试开发Python培训:模拟登录新浪微博-技术篇   一般一个初学者项目的起点就是登陆功能的自动化,而面临的项目不同实现的技术难度是不一样的,poptest在做测试开发培训中更加关注技术难点,掌握技 ...

  8. python获取函数名

    Date: 20140223Auth: Jin 参考: http://hi.baidu.com/greysign/item/d11919d325c4c2e6b2f777bf 获取函数名python中获 ...

  9. //可以不保存在session中, 并且前面我保存在request,这里session也可以获取 chain.doFilter(request, response); //只有登录名不为空时放行,防止直接登录 成功的页面

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...

随机推荐

  1. Golang实现mysql读库映射成Map【Easy】

    这个类库灵感来源于.net的dbHelper类,因为其简单易用,现在go的driver必须使用对象映射,这让人火大不爽,不能实现灵活的Map,在Key经常变动的业务场景里面非常不爽,我还是喜欢直接写s ...

  2. 01 Go 1.1 Release Notes

    Go 1.1 Release Notes Introduction to Go 1.1 Changes to the language Integer division by zero Surroga ...

  3. 基于timestamp和nonce的防止重放攻击方案

    参考:http://blog.csdn.net/koastal/article/details/53456696

  4. C# byte[] 转换16进制字符串

    1.byte[] 转换16进制字符串 1.1 BitConverter方式 var str = DateTime.Now.ToString(); var encode = Encoding.UTF8; ...

  5. java基础48 IO流技术(序列流)

    本文知识点目录: 1.SequenceInputStream序列流的步骤    2.实例    3.附录(音乐的切割与合并) 1.SequenceInputStream序列流的步骤 1.找到目标文件  ...

  6. 使用T-SQL导入多个文件数据到SQL Server中

    在我们的工作中,经常需要连续输入多个文件的数据到SQL Server的表中,有时需要从相同或者不同的目录中,同时将文件中的数据倒入.在这篇文章中,我们将讨论如何同时把一个目录中的文件的数据倒入到SQL ...

  7. 参数化SQL语句

    避免SQL注入的方法有两种:一是所有的SQL语句都存放在存储过程中,这样不但可以避免SQL注入,还能提高一些性能,并且存储过程可以由专门的数据库管理员(DBA)编写和集中管理,不过这种做法有时候针对相 ...

  8. OnClickListener接口

    package com.example.wang.testapp2; import android.support.v7.app.AppCompatActivity; import android.o ...

  9. 跟我一起学WPF(1):WPF的UI设计语言——XAML

    XAML是什么 XAML全称是Extensible Application Markup Language (可扩展应用程序标记语言),是专门用于WPF技术中的UI设计语言. XAML基础 XAML是 ...

  10. 001 Java 深拷贝、浅拷贝及Cloneable接口

    原本写过,后来在阅读的时候,感觉自己都不是太明白了,删除后参考人家的又重新写了一份. 一:开篇 1.复制一个变量 举例是int类型. 其他其中七种原始数据类型同样适用. 原始类型:boolean,ch ...