I have been working on some python code with a friend and for some reason i keep getting this message when i try to run his code,

if ar[2]!="client":
IndexError: list index out of range

I can't see whats wrong and i have never had this message come up before??

All there is to the client line is this : if ar[2]!="client":
Thats it there is nothing else there, i have asked my friend and he reckons it works for him. I have tried some examples i found on the net and if they have any "ar" in them they don't seem to work. I have tried uninstalling all my python stuff and doing a fresh install and that doesn't seem to make any difference either.

You need to put some elements into the ar list ...

ar = []  # empty list gives IndexError: list index out of range

#ar = ["cl", "cli", "clien"]  # properly loaded list will work

if ar[2]!="client":
    print "not client"

Edited 7 Years Ago by vegaseat: updated old [php] code tags

R now i see what's wrong, all i got to say is thank god there are sites like this and good people like you to help vegaseat :mrgreen:


P.S I'll see you when i come across my next problem ;)

This question has already been answered. Start a new discussion instead.