231321 发表于 2016-3-21 09:35:18

Python 基础 员工信息列表



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def query():
    staff_dic = {}
    f = file('stu_info.txt')
    for line in f.xreadlines():
      stu_id, stu_name, mail,company,title,phone = line.split()
      staff_dic =
    while True:
      query= raw_input('\033[32;1mPlease input the query string\033[0m').strip()
      if len(query) <3:
            print 'You have to input at least 3 letters to query!'
            continue
         
      match_counter = 0
      for k,v in staff_dic.items():
            index = k.find(query)
            if index != -1:
                print k[:index] + '\033,v
                match_counter +=1
            else:
                str_v = '\t'.join(v)
                index = str_v.find(query)
                if index != -1:
                  print k,str_v[:index] + '\033
                  match_counter +=1
                #for i in v: #going to do the fuzzy matchs
                #    if i.find(query) != -1: #found item
                #      str_v = '\t'.join(v)
                #      print k,str_v
                #      match_counter +=1
                #      break
                     
      print 'Matched \033[31;1m%s\033[0m records!' % match_counter
         
if __name__ == '__main__':
    query()



页: [1]
查看完整版本: Python 基础 员工信息列表