[Tutor] Python List Help

Mike Sweany mike at fozzil.net
Mon Oct 19 17:24:32 CEST 2009


Hi all, 

 

I am a PHP developer that just started learning Python for a specific
application and the transition has been pretty easily assisted by google,
but I just don’t see the issue with this one?

 

I’ve got a list that created and populate in a loop that shows the correct
info when I print it, but if I try to print array[0], it says the list index
is out of range.

 

Here is the code snippet. Basically, I have a link here that I am pulling
the href info from and splitting it up, only keeping the 5th value, which I
am then adding to the playerid array.

 

playerid = []

                for i in range(0, players):

                                player = playerlink[i]['href'] 

                                breakup = player.split('/')

                                playerid.append(breakup[4])

                                

                stats = test.findAll(text=True)

                print len(playerid) ß this shows the expected result

                print playerid[0] ßthis kills the script

 

 


   33         print len(playerid)


   34         print playerid[0]


   35         

	

playerid = []

<type 'exceptions.IndexError'>: list index out of range 
      args = ('list index out of range',) 
      message = 'list index out of range' 

If I change the print playerid[0] to print playerid[1], same error, but if I
change it to print playerid[2] or higher, it will show the same error, but
the playerid= [] will show the actual list values in the debug.

Any help would be appreciated, thank you!

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091019/54b7089c/attachment-0001.htm>


More information about the Tutor mailing list