\'int\'对象是不可下标的

问题描述

| 我已经在网上搜索了近一个小时,但找不到任何东西。但是我离题了,第6行继续返回
TypeError: \'int\' object is unsubscriptable
。请帮助我确定是什么原因造成的。
def __reassigner__(allL,currentRow,currentSpace):
    changingRow=currentRow+1
    newl=[-1]*24
    while changingRow<8:
        distance = changingRow-currentRow
        newl[8:15]=allL[changingRow[0:7]]  #Line 6,this one
        if newl[currentSpace]==-1:
           newl[currentSpace]= currentRow
         if newl[currentSpace-distance]==-1:
           newl[currentSpace-distance]= currentRow
        if newl[currentSpace+distance]==-1:
           newl[currentSpace+distance]= currentRow
        allL[changingRow[0:7]]=newl[8:15]
        changingRow+=1
    return(allL)
    

解决方法

        变量
changingRow
是一个整数,但是您尝试用with3ѭ对其进行切片。由于int不允许执行此操作,因此会出现错误。 我不知道你打算用那条线。也许
allL
是一个列表列表,而您想要
allL[changingRow][0:7]
?     ,        您的代码中的ѭ2seems似乎是一个整数(我假设在行之后表示
changingRow=currentRow+1
)。不幸的是,在第6行中,您尝试获得:
changingRow[0:7]
,该行不起作用,因为您试图将整数值当作数组来访问。     ,        
changingRow
是整数。 “ 3”将提取类似列表(\“ subscribeable \”)的对象的前7个元素,但是“ 11”没有像列表和字符串中的元素那样的“元素”。 您想通过ѭ3达成什么目标?     ,        changingRow是一个整数,您不能从中取0-7     ,        您不能访问写
changingRow[0:7]
,因为changeingRow是一个整数。如果必须使用切片符号(前8位或类似数字)访问它,则可以执行
str(changingRow)[0:7]
,但您可能会遇到设计问题。