Ctypes,IndexError:列表索引超出范围

时间:2016-06-20 18:35:57

标签: python ctypes python-3.5

范围是20,所以我不确定这个错误来自哪里。添加了打印列表长度

错误在第二行。我如何调用代码:

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

打印长度显示159

StreamingParameterList()内容

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

确切错误:

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

1 个答案:

答案 0 :(得分:2)

您的范围不是20,这是您的索引超出界限的唯一方式。它是空的还是小于15。

您可以通过在第二行之前立即添加此内容来验证这一点:

print len(plist)

这将验证长度不大于15