I have successfully created a program that searches for a word in multiple files but now I need to be able to search by more than one word. I have add code from a previous discussion to my original program but I am unsure how they should fit together. Can someone clear this up for me?
[code=python]
#!C:\PYTHON25\P YTHON.EXE
import os
import re
dir_name= r'c:\Python25\b ooks\books\book s'
word=raw_input( "Enter a word to search for: ")
word2=raw_input ("Enter a second word to search for: ")
keyList = ['word', 'word2']
entryList = [os.path.join(di r_name, fn) for fn in os.listdir(dir_ name) if os.path.isfile( os.path.join(di r_name, fn))]
for file_name in entryList:
for line in file(file_name) .readlines():
if word in line:
print line
patt = re.compile('|'. join(keyList), re.IGNORECASE)
for fn in dir_name:
f = open(fn)
for line in f:
if patt.search(lin e.lower()):
print line
f.close()
[/code]
[code=python]
#!C:\PYTHON25\P YTHON.EXE
import os
import re
dir_name= r'c:\Python25\b ooks\books\book s'
word=raw_input( "Enter a word to search for: ")
word2=raw_input ("Enter a second word to search for: ")
keyList = ['word', 'word2']
entryList = [os.path.join(di r_name, fn) for fn in os.listdir(dir_ name) if os.path.isfile( os.path.join(di r_name, fn))]
for file_name in entryList:
for line in file(file_name) .readlines():
if word in line:
print line
patt = re.compile('|'. join(keyList), re.IGNORECASE)
for fn in dir_name:
f = open(fn)
for line in f:
if patt.search(lin e.lower()):
print line
f.close()
[/code]
Comment