[Tutor] this is ugly
Charlie Clark
charlie at begeistert.org
Tue Oct 21 15:27:49 EDT 2003
>
> > Can line 3 of the following be improved (especially since I might
want
> > to search for even more strings within each line):
>
> > myfile=open(r'F:\logs\myfile.txt', 'r')
> > for line in myfile.readlines():
> > if line.find("KeC 923") != -1 or line.find("ZEF 156") != -1 or
> > line.find("pBX 88347") != -1 or line.find("FZX 17255") != -1:
> > #code if found
These methods are fine but regular expressions are much better for this
task. Danny Yoo gave me some help on using re.compile() earlier this
year so if you check the archives you should find what you need.
Charlie
More information about the Tutor
mailing list