模糊查询姓名并高亮
#!/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