y45t4r3 发表于 2015-1-4 09:03:08

Python下实现文件中的全文搜索小测试

username = 'test'
password = '123456'

while True:
    user_str = raw_input("Please input your name>>")
    pass_str = raw_input("Please input your password>>")
    if username != user_str or password != pass_str:
      print "Sorry,You input wrong username or password!"
      continue
    else:
      print "Login successfully!"
      while True:
            flag = 0
            input_str = raw_input("Please input name what do you to search>>")
            filestr = open('D:/myPython/name_list.txt','rb+')
            if input_str == 'exit' or input_str == 'quit':
                filestr.close()
                exit()
            elif input_str == 'list all':
                line_str = filestr.readline()
                while len(line_str) != 0:
                  line_str = line_str.strip('\n')
                  print line_str
                  line_str = filestr.readline()
                flag = 1

            while True:
                line = filestr.readline()
                if len(line) == 0:
                  break
                line = line.strip('\n')
                line_behind = line.split(' ')
                if input_str in line:
                  print line
                  flag = 1
                else:
                  pass
            if flag != 1:
                print "Sorry,%s has found." %input_str

测试的要求如下:
1:验证登录
2:读取信息文件列表
3:全文搜索功能,包括精确匹配,模糊查找,遍历打印,退出功能

这是我对自己最近学习Python的一个小测试吧,可能会存在问题,大家如有发现,敬请指出。

页: [1]
查看完整版本: Python下实现文件中的全文搜索小测试