广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python下实现文件中的全文搜索小测试
  • 348
分享到

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

文件小测试全文 2023-01-31 02:01:23 348人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

username = 'test' passWord = '123456' while True: user_str = raw_input("Please input your name>>") pass_str = r

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的一个小测试吧,可能会存在问题,大家如有发现,敬请指出。

--结束END--

本文标题: Python下实现文件中的全文搜索小测试

本文链接: https://www.lsjlt.com/news/186476.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作