don't understand error message

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Sep 17 05:12:06 EDT 2002


Manuel Hendel <manuel at hendel.net> wrote in 
news:mailman.1032251060.4906.python-list at python.org:

> I do the following,
> 
> domains = []
> 
> for line in lines:
>     line = string.strip(line)[1:-1]
>     fields = string.split(line, "|")
>     if fields[3] not in domains:
>         domains.append(fields[3])
> 
> error:
> 
> Traceback (most recent call last):
>   File "./pop3create.py", line 16, in ?
>     if fields[3] not in domains:
> IndexError: list index out of range
> 

It simply means that at least one line of your file doesn't have 4 fields 
after you have finished your processing. If the line only has two "|" 
characters in it, then you will only get three fields which you can access 
with indices 0 to 2. Trying to use an index out of range for a list will 
produce this error.

Try sticking a "print fields" line just before the if statement, the last 
line printed will show you which line didn't match.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list