[Tutor] Parsing a file
Bob X
bobx@linuxmail.org
Sat, 16 Mar 2002 02:44:20 +0800
I have this:
# import the libs
import sys
inp = open(sys.argv[1],"r")
outp = open(sys.argv[2],"w")
kw = ["tony","bob","chris"] # build list of keywords
# loop through the kw list and print the lines to a file
for line in inp.readlines():
for badword in kw:
if line.find(badword) > -1:
print line
outp.write(line)
break
# close the files
inp.close()
outp.close()
# let me know when it's done doing its thang
print "Finished processing file..."
Which works great. Can I change "print line" to "print kw + line" to get the keyword it found plus the line it found it on or is it harder than that?
Bob
--
Get your free email from www.linuxmail.org
Powered by Outblaze