[Tutor] Script to search in string of values from file A in file B
Dave Angel
d at davea.name
Wed May 9 17:38:44 CEST 2012
<SNIP>
>
>
> If you really have to handle the case where there is a final key with no
> data, then you'll have to detect that case, and make up the data
> separately. That could be done with a try block, but this is probably
> clearer:
>
> rawlines = object.readlines()
> if len(rawlines) %2 != 0:
> rawlines += "" #add an extra line
Oops, that should have been
rawlines.append("") or maybe rawlines.append("\n")
> lines = iter(rawlines)
>
> for keyline in lines:
> linedata = lines.next()
> for word in searches:
> if word in keyline:
> print word, "-->", linedata
>
>
--
DaveA
More information about the Tutor
mailing list