parsing - Python parse only specific parts of text file -
i have text file containing lots of data looks this:
logstart . . . (chunk of data) logend . . . logstart . . . (chunk of data) logend . . . times logstart . . . (chunk of data) logend . . . times logstart . . . (chunk of data) logend . . .
i want python code open file , read chunks of data if , if there "times" associated right below "logend". if there no times chunk want ignore it. , when reads correct chunks of data want read times associated it.
this had before realized needed extract parts (which saved entire text file 'lines'):
lines = [] open(filename, 'rt') in_file: line in in_file: lines.append(line)
how can change 'lines' specific parts of file?
something this:
lines = [] open(filename, 'rt') in_file: chunk = [] line in in_file: chunk.append(line) if(line.find('times')>=0): lines.extend(chunk) if(line.find('logstart')>=0): chunk = []
wiki
Comments
Post a Comment