Parsing & question about usages off classes!

Dennis Lee Bieber wlfraed at ix.netcom.com
Sun Nov 3 18:32:58 EST 2002


Frans fed this fish to the penguins on Sunday 03 November 2002 01:14 pm:

> 
> I want to make a program which uses analogs computer output. From the
> output I want to create nice websites with graphics.
> 
> Example lines off analogs computer output:
> 
>                   R       P       ----   DATE ----------------
> D     RP      901     133     2002    09      18
> H     RP      6       6       2002    10      26      00
> W     RP      3347    662     2002    10      06
> 
> 
> D H w being differnt reports. RP meaning Request and Pages. Now I need
> to read all these lines into python and then do stuff to extract the
> data.
>
        Okay, now we are getting something easy...

        Are D, H, W the ONLY categories? If so, you could just hardcode and 
use IF statements.


#initialize lists
daily_list = []
hourly_list = []
weekly_list = []

#read data line

# split/process
tmp = string.split(logline, "\t")
category, RPfield, rfield, pfield, datetime = tmp[0], tmp[1], tmp[2], 
tmp4, string.join(tmp[5:], ":") #all is one line of course

if category == "D":
        daily_list.append([RPfield, rfield, pfield, datetime])
elif category == "H":
        hourly_list.append...
elif category == "W":
        weekly_list.append...
else:
        print "UNKNOWN CATEGORY '%s' SEEN" % category

        -=-=-=-=-=-=-

        Next step up, again assuming you know all the categories:

#initialize
theLists = { 'D':[], 'H':[], 'W':[] }

#read data line

#split/process
tmp = string.split(logline, "\t")
category, RPfield, rfield, pfield, datetime = tmp[0], tmp[1], tmp[2], 
tmp4, string.join(tmp[5:], ":") #all is one line of course

try:
        theLists[category].append([RPfield, rfield, pfield, datetime])
except:
        print "UNKNOWN CATEGORY '%s' SEEN" % category


        -=-=-=-=-=-=-

        Next step up again, if you DON'T know all the categories:

#initialize
theLists = {}

#read data line

#split/process
tmp = string.split(logline, "\t")
category, RPfield, rfield, pfield, datetime = tmp[0], tmp[1], tmp[2], 
tmp4, string.join(tmp[5:], ":") #all is one line of course

if not theLists.has_key(category):
        theLists[category] = []
theLists[category].append([RPfield, rfield, pfield, datetime])


--  
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list