代码语言:javascript复制
#!/usr/bin/python3
#luck
import sys
filename = input('请输入您要搜索的路径及文档名称:')
if len(filename) == 0:
sys.exit('不能为空!')
while True:
mubiao = input('请输入您要搜索的关键词:')
if mubiao == 'exit':
sys.exit('欢迎使用搜索系统!')
if len(mubiao) == 0:
continue
mubiao2 = input('请输入第二个关键词,忽略按Enter:')
if len(mubiao2) == 0:
with open(filename) as f:
Num = 0
for line in f:
line = line.strip('n')
index = line.find(mubiao)
if index > -1:
Num = 1
print (line[:index] ('