Problem with lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WIWA

    Problem with lists

    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.p y", line 18, in
    lijst.append(in t(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.sp lit(line)
    datum=string.sp lit(words[3],':') # datum bevat de volledige datum:
    [16/Sep/2003:05:22:57 +0200]
    lijst.append(in t(datum[1]))

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

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

    f.close()
  • David C. Fox

    #2
    Re: Problem with lists

    WIWA wrote:
    [color=blue]
    > 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.p y", line 18, in
    > lijst.append(in t(datum[1]))
    > IndexError: list index out of range
    >[/color]

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

    David

    Comment

    • Erik Max Francis

      #3
      Re: Problem with lists

      WIWA wrote:
      [color=blue]
      > 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.[/color]

      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.
      [color=blue]
      > Question: do lists have a limit? Anyone know how I can change this
      > simple script so that it works for more entries as well.[/color]

      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 && [email protected] && 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

      Comment

      Working...