首页 > 代码库 > Python下实现文件中的全文搜索小测试
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的一个小测试吧,可能会存在问题,大家如有发现,敬请指出。
本文出自 “星空孤魂” 博客,请务必保留此出处http://mysqldba.blog.51cto.com/6728219/1598360
Python下实现文件中的全文搜索小测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。