I'm pretty new to python but thought I'd write something to read this log file to try and learn it. Ideally, it will read this log file, match a string and return everything between the "****" delimiters where the string was matched. I'm not 100% sure how to go about this though. I populate my tuple with the following, but can't see how I display the lines inbetween the delimiter objects.
def look(self): NULL = None data = [(0,0,0,0)] ## (LINE #, STRING, Match_Obj, Del_Obj) segment = re.compile('[*****]') lookfor = re.compile('[COMMS_MESSAGE_SENT]') LineNum = 0 for line in self.thefilesText: obj = lookfor.match(line) deli = segment.match(line) data.append((LineNum,line,obj,deli)) LineNum += 1 return data
I could be going about this the wrong way. Should I be segmenting the log file fist (between delimiters), eg, 1 segment per list element
and then using RE to search the segments (then return the entire segment when found).
any input would be great!