2011-06-11 175 views
-2

我在网上搜索了近一个小时,但找不到任何东西。但是我离题了,第6行一直回到TypeError: 'int' object is unsubscriptable。请帮我确定是什么原因造成的。'int'对象不可订阅

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) 
+1

与您的问题无关,但名称\ _ \ _包围\ _ \ _通过双下划线应该用于Python的内置功能和[样式指南](http://www.python.org/dev/peps/pep-0008 /)禁止创建自己的。 – 2011-06-11 23:16:05

回答

4

变量changingRow是一个整数,但你尝试用changingRow[0:7]切片它。由于整数不允许执行此操作,因此会出现错误。

我不知道你的意图是什么与该行。也许allL是一个列表清单,你要去allL[changingRow][0:7]

+0

谢谢!你确实很好地诊断出这部分代码现在可以工作。凉! – BearFury 2011-06-11 23:22:03

0

changingRow在你的代码似乎是一个整数(我假设行后说changingRow=currentRow+1)。不幸的是,在第6行中,您尝试获取:changingRow[0:7],这不起作用,因为您试图像访问数组一样访问您的整数值。

0

changingRow是一个整数值。 changingRow[0:7]将提取类似列表(“可下标”)对象的前7个元素,但int没有像列表和字符串中那样的“元素”。

你想用changingRow[0:7]实现什么?

0

changingRow是一个整数,你不能拿的indeces 0-7从中

0

,你不能访问写changingRow[0:7]因为changingRow是一个整数。如果您必须使用切片符号(前8位数字或某物)访问它,则可以执行str(changingRow)[0:7],但您可能有设计问题。