1
저는 Python을 처음 접했고 다음 문제를 해결하려고합니다. 단어 목록을 반복하고 파일에서 찾아보고 싶으면 단어가있는 행 번호를 찾으십시오.Python - 목록의 값에서 파일 검색
files = glob.iglob(os.path.join(in_dir, '*.*'))
List = ['word1', 'word2',...'wordn']
for index, word in enumerate(List):
print(index, word)
for item in files: # Iterate all files in Input directory
filename = os.path.basename(item) # Copy the filename without the path
print('file: {0}'.format(filename))
with open(item, 'r') as f:
for num, line in enumerate(f, 0):
if word in line:
print('num: {0}, line: {1}'.format(num, line))
하지만 작동하지 않는 것 같습니다. 목록의 첫 번째 값만 검색했습니다. 내가하고 싶은 일은 모든 파일의 모든 List 값을 검색하는 것입니다.
OMG !!! @mathewguest 많이 일을 감사드립니다! – Maki