list-模糊查询姓名并高亮程序

模糊查询姓名并高亮

#!/usr/bin/env python

staff_dic={}

f=file('stu_info.txt')

for line in f.xreadlines():

  stu_id,stu_name,mail,company,title,phone=line.split()

 staff_dic[stu_id]=[stu_name,mail,company,title,phone]

 

while True:

 query=raw_input('\033[32;1mPlease input the querystring\033[0m').strip()

  if len(query)< 3:

    print 'you haveto input at least 3 letters to query'

    continue

  match_counter = 0

  for k,v instaff_dic.items():

   index=k.find(query)

    if index != -1:

      printk[:index]+ '\033[32;1m%s\033[0m' %query +k[index+len(query):],v

      match_counter+=1

    else:

     str_v='\t'.join(v)

     index=str_v.find(query)

      if index != -1:

        printk,str_v[:index]+ '\033[32;1m%s\033[0m' %query +str_v[index+len(query):]

       match_counter +=1

#      for i inv:#going to do the fuzzy matchs

#        ifi.find(query) !=-1:#find item

#         str_v='\t'.join(v)

#          printk,str_v

#         match_counter +=1

#          break

  print 'Matched\033[31;1m%s\033[0m records!' %match_counter

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS