python简单查询用户
2014-01-23 21:47
513 查看
一,第一种:
采用文件中contact.txt中第一行读出后,将其分割成列表,然后对其判断,但是不支持部门查询。
采用文件中contact.txt中第一行读出后,将其分割成列表,然后对其判断,但是不支持部门查询。
#!/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 i 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第二种:将文件中每行读出后成字符串的形式,因此支持各个字段查询。
#!/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"第三种:用字典的方式来实现
#!/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
相关文章推荐
- 超简单的 Python 根据用户ip查询位置
- 小白学Python(四) 简单的用户管理系统v0.2
- Python简单的用户交互
- [Python3] 初识py, 一个简单练手的小玩意. 快递查询
- 用python写一个简单的用户登陆程序(要求写成函数)
- python--字典--实战分析--用户信息查询接口设计
- python 的变量和注释及简单的用户交互
- Python--简单的用户管理系统
- 采用python实现简单QQ单用户机器人的方法
- python简单用户管理模拟
- Python爬虫股票评论,snowNLP简单分析股民用户情绪(草稿)
- 编程语言的学习 ------ python3文件读取+用户登录简单验证+列表验证用户(优化3)
- Python实现简单快递查询
- python实现人人网用户数据爬取及简单分析
- Python实现简单的用户登录
- TensorFlow 安装最简单的办法 —— 针对 python 用户
- 教你用Python爬虫股票评论,简单分析股民用户情绪
- 学习python 第三季:编写简单简单连接数据库并执行查询操作
- [python]print简单用法和读取用户输入
- Python ORM框架SQLAlchemy学习笔记之安装和简单查询实例