[Tutor] IndexError:list index out of range

DavidCraig@pia.ca.gov DavidCraig@pia.ca.gov
Mon, 17 Dec 2001 10:02:52 -0800


I am using Idle on WIN 98.  I have the following program:

######################################################
#split and interactively page a string or file of text;
######################################################

import string

def more(text, numlines=15):
    lines=string.split(text, '\n')
    while lines:
        chunk=lines[:numlines]
        lines=lines[numlines:]
        for line in chunk:print line
        if lines and raw_input('More?') not in ['y', 'Y']:break

if __name__=='__main__':
    import sys                           #when run, not imported
    more(open(sys.argv[1]).read(), 10)   #page contents of file on cmdline

Every time I try to run it I get the following error message.

raceback (most recent call last):
  File "C:/Python21/Practice/more.py", line 17, in ?
    more(open(sys.argv[1]).read(), 10)   #page contents of file on cmdline
IndexError: list index out of range

I am unable to find the problem.  How is this out of range and what does
the error message mean?

TIA

Dave

D. H. Craig, CSM

D. H. Craig, CSM