Python help - Parsing Packet Logs -


i'm writing simple program that's going parse logfile of packet dump wireshark more readable form. i'm doing python.

currently i'm stuck on part:

for in range(len(linelist)): if '### server' in linelist[i]:     #do server parsing stuff      packet = linelist[i:find("\n\n", i, len(linelist))] 

linelist list created using readlines() method, every line in file element in list. i'm iterating through occurances of "### server", grabbing lines after until next empty line(which signifies end of packet). must doing wrong, because not find() not working, have feeling there's better way grab between ### server , next occurance of blank line.

any ideas?

looking @ thefile.readlines() doc:

file.readlines([sizehint])

read until eof using readline() , return list containing lines read. if optional sizehint argument present, instead of reading eof, whole lines totalling approximately sizehint bytes (possibly after rounding internal buffer size) read. objects implementing file-like interface may choose ignore sizehint if cannot implemented, or cannot implemented efficiently.

and file.readline() doc:

file.readline([size])

read 1 entire line file. trailing newline character kept in string (but may absent when file ends incomplete line). [6] if size argument present , non-negative, maximum byte count (including trailing newline) , incomplete line may returned. empty string returned when eof encountered immediately.

a trailing newline character kept in string - means each line in linelist contain @ one newline. why cannot find "\n\n" substring in of lines - a whole blank line (or empty 1 @ eof):

if myline in ("\n", ""):     handle_empty_line() 

note: tried explain find behavior, pythonic solution looks different code snippet.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -