TAGS :Viewed: 9 - Published at: a few seconds ago

[ Ctypes, IndexError: list index out of range ]

The range is 20 so I'm not sure where this error is coming from. Added print list length

Error is in the second line. How I call the code:

plist = StreamingParameterList()
print(len(plist))
plist = [plist[x] for x in [2,4,12,13,14]]

Print length shows 159

StreamingParameterList() contents

def StreamingParameterList():
    """ returns a list of all available streaming parameter names """
    num, length = get_parameter_list_size()
    splist = []

    for id in range(num):
        splist.append(get_parameter_list_item(id, length)[0])

    return splist

exact error:

Traceback (most recent call last):
  File "testStream.py", line 27, in (module)
    plist = [plist[x] for x in [2,4,12,13,14]]
  File "testStream.py", line 27, in (listcomp)
    plist = [plist[x] for x in [2,4,12,13,14]]
IndexError: list index out of range

Answer 1


Your range is not 20, that's the only way your index can be out of bounds. Either it is empty or it is less than 15.

You can verify this by adding this immediately before the second line:

print len(plist)

This will verify that the length is not greater than 15