-1

我用 Squish 写了一段 Python 代码。这是一段代码,它说错误是:这是什么意思?

数组 = [["1,6", "3,0", "7,0", 'null', True,]]

(columnEnd - columnStart) = 10

for循环的开始

for r in range(len(array)):
        waitForObjectItem(object_id, str(r + rowStart) + "/" + str(columnStart))
        clickItem(waitForObject(object_id), str(r + rowStart) + "/" + str(columnStart), 0, 0, 0, Qt.LeftButton);

        for c in range(columnEnd - columnStart)
            # Getting an error at this point , if loop
            if array[r][c] != 'null':
                print "array index is : {}".format(array[r][c])
                print "row is {}".format(r)
                print "column is {}".format(c)
                dataType = array[r][c].__class__
                print "dataType is {}".format(dataType)
                checkState = item_checks(object_id, r + rowStart, c + columnStart).checkState;               
                print "checkstate is {}".format(checkState)
                if (dataType == str and (checkState == "uncheckable" or checkState == "unknown")):
                    waitForObjectItem(object_id, str(r + rowStart) + "/" + str(c + columnStart))
                    doubleClickItem(waitForObject(object_id), str(r + rowStart) + "/" + str(c + columnStart), 1, 1, 0, Qt.LeftButton)
                    widget = "{type='QWidget' unnamed='1' container='" + object_id + "'}";
                    txt = array[r][c]
                    txtString = str(txt)
                    type(waitForObject(widget), "<DEL>")
                    type(waitForObject(widget), str(array[r][c]))
                    try:
                          type(waitForObject(widget), str("<TAB>"))
                    except Exception(err):
                        raise Exception ("Error is found :- {}".format(err))
                elif ((array[r][c] == True or array[r][c] == False) and (checkState != "uncheckable" and checkState != "unknown")):
                    print "data type boolean loop"
                    waitForObjectItem(object_id, str(r + rowStart) + "/" + str(c + columnStart))
                    if (array[r][c] != (item_checks(object_id, r + rowStart, c + columnStart).checkState == "checked")):
                        rowHeight = waitForObject(object_id).rowHeight(r + rowStart)
                        clickItem(waitForObject(object_id), str(r + rowStart) + "/" + str(c + columnStart), 10, rowHeight / 2, 0, Qt.LeftButton)
                        
                else:
                    raise Exception(object_id + ": dataType '" + str(dataType) + "' doesen't match to expected one of cell or is unknown or unhandled")
4

1 回答 1

1

您的“数组”在第一个位置只有五个条目。

但是因为你(columnEnd - columnStart)是 10,c在 0 到 9 的范围内,所以 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)。因此,当c达到 5 时,您的数组在索引 5 处没有条目,然后出现“列表索引超出范围”错误。

如果(columnEnd - columnStart)是 5,那么它会起作用。

如果你想遍历整个数组,array[r]你可以使用

for c in range(len(array[r])):
    if(array[r][c] ...):

确保它c在您的数组长度范围内,并且您的数组可以有不同的长度。

于 2016-04-28T07:18:31.250 回答