如何解决\'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]
,但您可能会遇到设计问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。