Problem with lists

Discussion in 'Python' started by WIWA, Aug 25, 2003.

  1. WIWA

    WIWA Guest

    Hi,

    I'm writing an application to analyse my Apache access_log file. In
    the below script (which is based on an example I found in 'How to
    think as a Programmer'-) I want to measure the amount of hits per
    hour. I know it is not the best algorithm but it works for now.

    I see some strange things: on rather small (it must be +/- < 4000 )
    entries in the access_log, my script works fine. Above this limit, I
    get the following error.

    Traceback (most recent call last):
    File "hits_per_uur.py", line 18, in
    lijst.append(int(datum[1]))
    IndexError: list index out of range

    Question: do lists have a limit? Anyone know how I can change this
    simple script so that it works for more entries as well.

    ------------------------------------------------------------------------------
    import sys,string

    def inbucket(lijst, low, high):
    count=0
    for num in lijst:
    if low<=num<high:
    count=count+1
    return count

    f=open('c:/summary.txt','a',1)
    f.write("Hits per uur" + "\n")

    lijst=['']*0
    data=sys.stdin.readlines()
    for line in data:
    words=string.split(line)
    datum=string.split(words[3],':') # datum bevat de volledige datum:
    [16/Sep/2003:05:22:57 +0200]
    lijst.append(int(datum[1]))

    numbuckets=24
    buckets= [0]*numbuckets
    bucketwidth=24/numbuckets
    for i in range(numbuckets):
    low=i* bucketwidth
    high=low+bucketwidth
    buckets=inbucket(lijst,low,high)

    for num in range(len(buckets)):
    output=str(num) + "\t" + str(buckets[num]) + "\n"
    f.write(output)

    f.close()
    WIWA, Aug 25, 2003
    #1
    1. Advertising

  2. WIWA

    David C. Fox Guest

    WIWA wrote:

    > Hi,
    >
    > I'm writing an application to analyse my Apache access_log file. In
    > the below script (which is based on an example I found in 'How to
    > think as a Programmer'-) I want to measure the amount of hits per
    > hour. I know it is not the best algorithm but it works for now.
    >
    > I see some strange things: on rather small (it must be +/- < 4000 )
    > entries in the access_log, my script works fine. Above this limit, I
    > get the following error.
    >
    > Traceback (most recent call last):
    > File "hits_per_uur.py", line 18, in
    > lijst.append(int(datum[1]))
    > IndexError: list index out of range
    >


    The error could be in datum[1]. Did you double-check that datum has at
    least two elements?

    David
    David C. Fox, Aug 25, 2003
    #2
    1. Advertising

  3. WIWA wrote:

    > I see some strange things: on rather small (it must be +/- < 4000 )
    > entries in the access_log, my script works fine. Above this limit, I
    > get the following error.


    It probably means that there's an entry in the log that isn't what you
    expect. The error is being generated by the input data; print the
    contents of `datum' before you run that code, or check it out in a
    debugger, to see what it contains.

    > Question: do lists have a limit? Anyone know how I can change this
    > simple script so that it works for more entries as well.


    No, lists do not have any such limitation. The code that's generation
    the exception isn't dealing with a large list, anyway.

    --
    Erik Max Francis && && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ It's just a day that brings it all about
    \__/ Sade
    Erik Max Francis, Aug 25, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    300
    JustSomeGuy
    Jun 17, 2004
  2. Jon Slaughter

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    400
    Buster
    Dec 13, 2004
  3. Charlotte Henkle

    Counter for items in lists in lists?

    Charlotte Henkle, Sep 25, 2004, in forum: Python
    Replies:
    8
    Views:
    385
    Charlotte Henkle
    Sep 26, 2004
  4. robin
    Replies:
    10
    Views:
    528
    Dave Hansen
    Apr 12, 2006
  5. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    379
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
Loading...

Share This Page