#需求
Users can Blur query employee information
Show how many matches, matching characters need high brightness display
#脚本内容
#!/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)
#员工信息表展示
[email protected] opt]# cat info.txt wsyht 1315326095 Yaowan [email protected]peter 1823572871 Duowan [email protected] Jack 15832908124 Tanwan [email protected]jenkis 17937829012 Haowan [email protected]
#脚本执行展示
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/83/F9/wKiom1eCUOngyGRXAADBEY7Zj94295.png-wh_500x0-wm_3 -wmp_4-s_4118538530.png "title=" qq picture 20160710214447.png "alt=" Wkiom1ecuongygrxaadbey7zj94295.png-wh_50 "/>
This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1821157
Fuzzy matching of Employee Information table with list under Python