[Tutor] How to put two things together and then print to a file?

Bob X bobx@linuxmail.org
Fri, 12 Apr 2002 01:21:09 +0800


The following works really great, except that I would like the word or words found to print first and then the line it was found on like so:

word "this is where the word was found"

Do I need to do a def to pass more than one thing to the outp.write? Something like:

def cachehit(badword, line):


=== current script ===

import sys, string

inp = open(sys.argv[1],"r")
outp = open(sys.argv[2],"w")

# build list of keywords
kw = ["word", "ape"]

# loop through the list and print the lines to a file
for line in inp.readlines():
    for badword in kw:
	if line.find(badword) > -1:
	    print badword,line	# print word and line
	    outp.write (line) # write line found
 
# close the files
inp.close()
outp.close()

# let me know when it's done doing its thang
print "Finished processing file..."
-- 

Get your free email from www.linuxmail.org 


Powered by Outblaze