Python下用List对员工信息表进行模糊匹配
2016-07-10 21:44
681 查看
#需求
用户可以模糊查询员工信息
显示匹配了多少条,匹配字符需要高亮度显示
#脚本内容
#员工信息表展示
#脚本执行展示
用户可以模糊查询员工信息
显示匹配了多少条,匹配字符需要高亮度显示
#脚本内容
#!/usr/bin/env python #_*_ coding:utf-8 _*_ while True: info = 'info.txt' f = file(info) search=raw_input('Please Engter You Search Info: ') for line in f.readlines(): i=line.strip().split() q=i[0] w=i[1] e=i[2] r=i[3] g=len(search) #第1列文件模糊匹配 if search in q: d=len(q) c=q.find(search) j=c+g if c == 0: u=q[:g] o=q[g:] print "\033[31m%s\033[0m%s %s %s %s" % (u,o,w,e,r) elif j == d: u=q[:c] o=q[c:d] print "%s\033[31m%s\033[0m %s %s %s" % (u,o,w,e,r) else: u=q[:c] o=q[c:j] p=q[j:] print "%s\033[31m%s\033[0m%s %s %s %s" % (u,o,p,w,e,r) #第2列文件模糊匹配 if search in w: d=len(w) c=w.find(search) j=c+g if c == 0: u=w[:g] o=w[g:] print "%s\033[31m %s\033[0m%s %s %s" % (q,u,o,e,r) elif j == d: u=w[:c] o=w[c:d] print "%s %s\033[31m%s\033[0m %s %s" % (q,u,o,e,r) else: u=w[:c] o=w[c:j] p=w[j:] print "%s %s\033[31m%s\033[0m%s %s %s" % (q,u,o,p,e,r) #第3列文件模糊匹配 if search in e: d=len(e) c=e.find(search) j=c+g if c == 0: u=e[:g] o=e[g:] print "%s %s\033[31m %s\033[0m%s %s" % (q,w,u,o,r) elif j == d: u=e[:c] o=e[c:d] print "%s %s %s\033[31m%s\033[0m %s" % (q,w,u,o,r) else: u=e[:c] o=e[c:j] p=e[j:] print "%s %s %s\033[31m%s\033[0m%s %s" % (q,w,u,o,p,r) #第4列文件模糊匹配 if search in r: d=len(r) c=r.find(search) j=c+g if c == 0: u=r[:g] o=r[g:] print "%s %s %s\033[31m %s\033[0m%s" % (q,w,e,u,o) elif j == d: u=r[:c] o=r[c:d] print "%s %s %s %s\033[31m%s\033[0m" % (q,w,e,u,o) else: u=r[:c] o=r[c:j] p=r[j:] print "%s %s %s %s\033[31m%s\033[0m%s" % (q,w,e,u,o,p)
#员工信息表展示
[root@localhost opt]# cat info.txt wsyht 1315326095 yaowan t891672832@126.com peter 1823572871 duowan t218460931@163.com jack 15832908124 tanwan t679312053@139.com jenkis 17937829012 haowan t357891241@qq.com
#脚本执行展示
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Shell 脚本编程陷阱