[Tutor] What am I missing?
Brian van den Broek
bvande at po-box.mcgill.ca
Mon Sep 27 17:07:36 CEST 2004
Hi Kent, Tom, and all,
Re-reading in the light of day, of course Kent is right. :-[
Sorry for giving a 'too late for thinking' answer, Tom.
Brian vdB
Kent Johnson said unto the world upon 2004-09-27 05:59:
> Brian,
>
> The variable found is assigned each time through the loop. re.search()
> will return either a Match object or None and found will have one of
> these values assigned to it. There is no need to re-assign a False value
> to found.
>
> Kent
>
> At 12:32 AM 9/27/2004 -0400, Brian van den Broek wrote:
>
>> Tom Tucker said unto the world upon 2004-09-26 23:58:
>>
>>> Good evening! Any thoughts on this one?
>>> The goal is to 'tail -f /var/log/messages' and if the line contains
>>> "CROND" for example, then print that line. The below script does a
>>> great job of tailing and printing, but it prints EVERYTHING.
>>> ##################
>>> #!/usr/bin/python
>>> import os, re
>>> findme = re.compile('CROND')
>>> logfile = os.system('tail -f /var/log/messages')
>>> for line in logfile:
>>> found = re.search(findme, line)
>>> if found:
>>> print line,
>>> else:
>>> print "not found"
>>> ####################
>>>
>>> Thanks,
>>> Tom
>>
>>
>> Hi Tom,
>>
<SNIP useless answer>
>> HTH,
>>
>> Brian vdB
More information about the Tutor
mailing list