...
fh = open(logfile)
while True:
line = fh.readline()
if not line: break
for r in res:
m = r.search(line)
if m:
counter += 1
break
fh.close()
...
I would write it as:
...
f = open(logfile)
for line in f:
for r in res:
m = r.search(line)
if m:
counter += 1
break
f.close()
...
or using the with construct:
...
with open(logfile) as f:
for line in f:
for r in res:
m = r.search(line)
if m:
counter += 1
break
...
When using the same regular expression in a loop, there is not reason to use the uncompiled one. (But this is the same in any language.)