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的一個小測試吧,可能會存在問題,大家如有發現,敬請指出。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章