appending to beginning of line
Bob X
bobx at linuxmail.org
Tue Oct 8 16:36:09 EDT 2002
More information about the Python-list mailing list
Tue Oct 8 16:36:09 EDT 2002
- Previous message (by thread): appending to beginning of line
- Next message (by thread): DBI cursor behaviour with multiple statements?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Terry Reedy wrote: > "Bob" <bobx at linuxmail.org> wrote in message > news:1001ff04.0210080422.1e373e13 at posting.google.com... > >># 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) # replace with > > >>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 "-". > > > Is this what you are looking for? > > for line in inFile.xreadlines(): > ok = True > for badword in kw: > if line.find(badword) > -1: > found = '%s %s\n' % (badword, line) > print found, # Print the result > outFile.write(found) # replace with > outfile.write(found+'n') # Write the result > ok = False > if ok: line = '- ' + line > print line, > outFile.write(line) > > Terry J. Reedy Errors out... File "D:\Robert\Projects\Python\inplace.py", line 51 outFile.write(found) # Write the result ^ SyntaxError: invalid syntax
- Previous message (by thread): appending to beginning of line
- Next message (by thread): DBI cursor behaviour with multiple statements?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list