appending to beginning of line

Anna revanna at mn.rr.com
Tue Oct 8 22:33:21 EDT 2002


On Tue, 08 Oct 2002 07:22:23 -0500, Bob wrote:

> 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
 
Okay - I admit it. I'm a complete newbie. So, I'm probably looking at
this far too simplistically. Why couldn't you just add something like
the following?

>   for badword in kw: 
>	if line.find(...
>	      found = '... 
>             print found           # Print the result

	else:
	  print "-"					# no bad word so print a placeholder

>       outFile.write(found)   		# Write the result

This is a question, rather than a suggestion.

Please don't flame if I've missed something completely obvious to the
experienced folks here. Any simple explanations of why this is unworkable
would be welcome. Thank you.

Anna



More information about the Python-list mailing list