[Tutor] Log analyzer

lonetwin lonetwin@yahoo.com
Sat, 15 Dec 2001 01:20:51 -0800 (PST)


Hi Mike,
    The split function takes an optional 'sep' argument which defaults to a
whitespace character. My usual way of doing things like this is:

fl = [ s.strip() for s in open(filename).readlines() ]
for line in fl:
    print line.split(',')

Remember tho' that if you are using a python version < 2.0 (i think ??) you'd
have to do something like:

fl=[]
for s in open(filename).readlines()
    fl.append(s.strip())
import string
for line in fl:
    string.split(line, ',')

hope that helps

--- Mike Yuen <myuen@ucalgary.ca> wrote:
> I'm trying to make a little log analyzer for myself and the problem is, I
> want to split each line which initially looks like:
> 
> FWIN,2001/09/14,01:44:53 -6:00GMT,24.68.251.251:137,24.53.33.12:137,UDP
> 
> I used the split function and got:
> 'FWIN,2001/09/14,01:44:53', '-6:00', 'GMT,<bunch of numbers here>'
> 
> I want each sections boundries to be BETWEEN the commas.  So, for example:
> FWIN is one section
> 2001/09/14 is another
> 01:44:53 -6:00GMT is yet another.
> 
> * Note: each sections size will vary in size.
> 
> I know I can take a another pass over the line but i've got literally
> 1000's of lines to process and taking 2 passes over each line really slows
> things done.  So, is  there an efficient way to split the lines?


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com