【发布时间】:2017-11-20 06:58:48
【问题描述】:
import os, sys
text = [file_search for file_search in os.listdir() if file_search.endswith('.txt') or file_search.endswith('.py')]
search = input()
print (text)
for files in text:
lines_list = open(files).read().lower().splitlines()
bool1 = False
for words in lines_list:
if bool1 == True:
break
elif words == search:
print (files)
bool1 = True
else:
bool1 = False
谁能告诉我哪里出错了?
【问题讨论】:
-
elif search in words: -
如果您使用
search in words,则无需将文件内容拆分为行。 -
即
if search in open(files).read().lower(): -
好的,我是新手,我有一个非常大的文件,比如 12 GB,我不想将所有文件都加载到内存中。一行一行就行了。
标签: python python-3.x search