[Tutor] this is ugly
Gregor Lingl
glingl at aon.at
Tue Oct 21 02:36:30 EDT 2003
Gerhard schrieb:
> Dear list
>
> 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
>
A quick suggestion:
if -1 not in [line.find(x) for x in ["KeC 923","ZEF 156","pBX
88347","FZX 17255"]]:
# etc.
(untested, of course)
Gregor
>
> Thanks
> Gerhard
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list