appending to beginning of line

Bob bobx at linuxmail.org
Tue Oct 8 08:22:23 EDT 2002


I have this script:

# loop through the list and print the lines to a file 
for line in inFile.xreadlines():
    for badword in kw:
        if line.find(badword) > -1:
            found = '%s %s' % (badword, line)
            print found            # Print the result 
            outFile.write(found)   # Write the result

This will print the badword and then the line it is on. For those
lines that do not contain a badword I want to place a hyphen "-".

Bob



More information about the Python-list mailing list