1 Replies - 805 Views - Last Post: 01 January 2015 - 11:51 AM Rate Topic: -----

#1 mark103  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

IndexError: list index out of range

Posted 01 January 2015 - 11:38 AM

Hi guys,
I need some basic help with my code, I've created a empty list to appending the controls to a list to add the controls when I pressed on the down arrow button of the keyboard. I'm trying to appending another controls to a list to add the controls when I press on the down arrow button again but i get an error: IndexError: list index out of range

When I try this:

    self.add_programs = list()
    self.rows += 1
    
    program_controls = xbmcgui.ControlButton(
        int(position_start), 
        int(position_top), 
        int(program_width), 
        int(program_height), 
        program_title, 
        focusTexture = self.path + self.button_focus, 
        noFocusTexture = self.path + self.button_nofocus,
        textColor ='0xFFFFFFFF',
        focusedColor ='0xFF000000'
    )
    self.add_programs[self.rows].append(ProgramControls(program_controls, program))




It give me the error: IndexError: list index out of range

The error are jumping on this line:

    self.add_programs[self.rows].append(ProgramControls(program_controls, program))


Here is the code:

   class ProgramControls(object):
         def __init__(self, control, program):
             self.control = control
             self.program = program


    class MyClass(xbmcgui.WindowXML):

        def __init__(self):
            self.add_programs = list()
            self.rows = 0
    
        def GoDown(self):
            self.add_programs = list()
            self.rows += 1
        
            program_controls = xbmcgui.ControlButton(
                int(position_start), 
                int(position_top), 
                int(program_width), 
                int(program_height), 
                program_title, 
                focusTexture = self.path + self.button_focus, 
                noFocusTexture = self.path + self.button_nofocus,
                textColor ='0xFFFFFFFF',
                focusedColor ='0xFF000000'
            )
            self.add_programs[self.rows].append(ProgramControls(program_controls, program))
        prog_button = [elem.control for elem in self.add_programs]


        if self.programs == False:
           self.addControls(prog_button)



Can you please help me how I can appending the controls to a list in each time when I press on the down arrow button of the keyboard to allow me to add the controls in each time?

If that is possible, please let me know.

Is This A Good Question/Topic? 0
  • +

Replies To: IndexError: list index out of range

#2 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10730
  • View blog
  • Posts: 18,359
  • Joined: 19-March 11

Re: IndexError: list index out of range

Posted 01 January 2015 - 11:51 AM

So you start with what you know: the value of rows is out of range for the list add_programs. And this makes sense, since the value of rows should be positive when this error happens (it's at least zero, plus one) but you've assigned add_programs to hold an empty list - so any assignment of the form add_programs[n] = foo is going to fail, and this is just one of those cases. You could append to add_programs, which should work, and looks like it does what you're trying to do in any case.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1