String Comparison Testing
gagsl-py2 at yahoo.com.ar
Wed Dec 24 19:55:33 CET 2008
En Wed, 24 Dec 2008 16:20:17 -0200, Brad Causey
<bcausey at zerodayconsulting.com> escribió:
> I am trying to do some basic log parsing, and well, I am absolutely
> at this seemingly simple problem. I am by no means a novice in python,
> yet this is really stumping me. I have extracted the pertinent code
> and modified them to function as a standalone script. Basically I am
> a log file ( in this case, testlog.log) for entries and comparing them to
> entries in a safe list (in this case, safelist.lst). I have spent
> hours doing this several ways and this is the most simple way I can come
I'd say the "\n" at the end of each line is the culprit.
> safelist = safelistfh.readlines()
safelist = [line.strip() for line in safelistfh]
(or just strip('\n') if spaces are important); same for the other list.
> def safecheck(line):
> for entry in safelist:
> print 'I am searching for\n'
> print entry
> print '\n'
> print 'to exist in\n'
> print line
repr() is your friend when debugging these things: print repr(entry) etc.
> comp = line.find(entry)
> if comp <> -1:
> out = 'Failed'
> out = 'Passed'
if entry in line: ...
Are you sure you're interested in the LAST comparison result ONLY?
More information about the Python-list