一,第一种:

采用文件中contact.txt中第一行读出后,将其分割成列表,然后对其判断,但是不支持部门查询。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
while True:
        name=raw_input('please input name:')
        if name == 'small':
                while True:
                        password=raw_input('please input password:')
                        if password == '123':
                                print 'welcome login  system'
                                while True:
                                        input=raw_input('please input employee name:')
                                        f=open('contact.txt','r')
                                        match=0
                                        for in f.readlines():
                                                if input == i.split(" ")[1]:
                                                        print i
                                                        match=1
                                        if match==0:
                                                        print "user not found,please input"
                                        f.close()
                                #break
                        else:
                                print 'password is wrong,try again'
                break

第二种:将文件中每行读出后成字符串的形式,因此支持各个字段查询。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python
while True:
        input = raw_input("please input your username:")
        if input == 'small':
                password = raw_input("please input your pass:")
                p = '123'
                while password != p:
                        password = raw_input("wrong passwd,input again:")
                else:
                        print "welcome login to linux!"
                while True:
                        match_yes = 0
                        input = raw_input("\033[32mPlease input name whom you want to search:\33[0m")
                        contact_file = file('contact_list.txt','r')
                        while True:
                                line = contact_file.readline()
                                if len(line) == 0:break
                                if input != "" and input in line:
                                        print "match item: \33{36,1m%s\033[0m" % line
                                        match_yes = 1
                        if match_yes == 0 :print "no match item found"

第三种:用字典的方式来实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
f=file('contact.txt')
personal={}
for line in f.readlines():
        name= line.split()[0]
        personal[name]=line
while True:
f=file('contact.txt')
personal={}
for line in f.readlines():
        name= line.split()[0]
        personal[name]=line
while True:
        input=raw_input('please input username:').strip()
        if len(input) == 0:continue
        if input in personal:
        #if personal.has_key(input):
                #print 'username information:  %s' %personal.get(input)
                print 'username information:  %s' %personal[input]
        else:
                print '%s not found,please input' %input

本文转自 deng304749970 51CTO博客,原文链接:http://blog.51cto.com/damondeng/1354239,如需转载请自行联系原作者

python简单查询用户相关推荐

  1. python 搭建登陆系统,用Python连接操作MySQL数据库,做一个简单的用户登录注册系统...

    我们可以很容易地用Python实现一个用户登录系统,相信这即使是对编程新手来说也是小菜一碟. 作为Python的小萌新,今天我想记录下来的是如何实现一个连接了MySQL数据库的用户登录注册系统,它的效 ...

  2. php和python交互-Python如何实现简单的用户交互程序(示例)

    本篇文章给大家带来的内容是关于Python如何实现简单的用户交互程序(示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 我们经常使用的程序都会有与用户交互的程序,比如网页的登录, ...

  3. 【数据库】SQL极速入门(多种方式查询用户复借次数)

      最近遇到这样一个事:许多DBA的小伙伴不太明白金融业务中复借用户的定义方式以及sql查询方式,给他们提需求也整不明白,需求如下:   根据订单编号,查询用户该订单所对应的复借次数(白话讲就是:我有 ...

  4. python db2查询_如何将DB2查询转换为python脚本

    python db2查询 Many companies are running common data analytics tasks using python scripts. They are a ...

  5. python简单的小程序_Python简单小程序---名片简易系统

    Python简单小程序---名片简易系统 主程序功能代码 import cards_tools while True: cards_tools.show_meun() action = int(inp ...

  6. 复习Java第一个项目学生信息管理系统 04(权限管理和动态挂菜单功能) python简单爬数据实例Java面试题三次握手和四次挥手生活【记录一个咸鱼大学生三个月的奋进生活】016

    记录一个咸鱼大学生三个月的奋进生活016 复习Java(学生信息管理系统04权限管理和动态挂菜单功能) 改写MainFrame的构造方法 新增LoginFrame的验证登录是否成功的代码 新增Logi ...

  7. Python 简单入门指北(试读版)

    本文是我小专栏中 Python 简单入门指北 一文的前半部分,如果你能坚持读完并且觉得有一定收获,建议阅读原文,只需一杯咖啡钱就可以阅读更精彩的部分,也可以订阅小专栏或者加入我的知识星球,价格都是 6 ...

  8. 简单mysql 查询_MySQL简单查询详解

    MySQL的查询操作 单表查询:简单查询 多表查询:连接查询 联合查询 布尔条件表达式操作符= 等值比较 <=>:跟空值比较不会产生额外信息的等值比较 <>:不等值 <: ...

  9. Python 简单入门指北(二)

    Python 简单入门指北(二) 2 函数 2.1 函数是一等公民 一等公民指的是 Python 的函数能够动态创建,能赋值给别的变量,能作为参传给函数,也能作为函数的返回值.总而言之,函数和普通变量 ...

  10. sql between包括两端吗_简单查询-SQL

    SQL基本的查询语句 1 select 语句 select 列名,列名--------select子句 from 表名;--------- from子句 书写规则: Select 语句中列名无需加引号 ...

最新文章

  1. 吉利蔚来造手机,小米造车
  2. AI大觉醒:图灵奖得主Bengio称AI将产生意识,未来机器学习核心是注意力机制
  3. GTK+图形化应用程序开发学习笔记
  4. python读数据-python数据读写
  5. C#枚举硬件设备(升级版)
  6. mysql 子查询 主键外键_MySQL查询优化:用子查询代替非主键连接查询实例介绍
  7. 真正理解红黑树,真正的
  8. 前端学习(2621):更新品牌
  9. JS正则表达式常见场景下的用法总结
  10. java三目运算符简化代码_如何使用传播运算符简化代码
  11. 阅读《平庸的世界》后感觉 (两)
  12. 每个人都应该读一读贝索斯的致股东信 1997-2016
  13. LESS----CSS预处理语言
  14. php mixed约束,Mixed Content: 混合被动/显示内容和混合活动内容
  15. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---工厂模式之简单工厂[转]
  16. docker login Error response from daemon: Get http://ip:port/v2/: net/http: request canceled
  17. 弹性伸缩系统的技术演进与落地实践
  18. goodFeaturesToTrack——Shi-Tomasi角点检测
  19. IIS8/IIS7/IIS6 出现ADODB.Connection 错误 '800a0e7a'的解决办法
  20. 嵌入式技术与应用专业毕业以后可以做什么?

热门文章

  1. atitit 面试问题表 侧重于项目和业务描述方面.v2 良好的标准:: 1.回答问题比较流畅,较少出现停顿现象,较少犹豫 2.回答有条理清晰 不杂乱 3.回答较为丰富内容 4.精神状态紧张
  2. Atitit 架构师之道 attilax著 1.1. 认和评估系统需求, 2 1.2. 给出开发规范 2 1.3. ,搭建系统实现的核心构架, 2 1.4. 扫清主要难点的技术人员 2 1.5. 核
  3. atitit 板块分类 上市公司 龙头企业公司 列表 attilax总结.docx
  4. Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理
  5. paip.FTP服务端及客户端的使用总结
  6. 美国:DFA(Dimensional fund advisors LP)基金介绍
  7. 走进爆发中的AIOps
  8. (转)全球最神秘的高频交易巨头Jump Trading
  9. 量化研究: Julia还是Matlab?
  10. 详解《云原生架构白皮书》,附下载链接