2014-12-03 72 views
-1

内部访问的元组我有一个二维数组,看起来就像这样:不能二维数组蟒蛇

[[(0, 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0)], [(0, 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0)]] 

我想从这样一个给定的小区接入元组的值:

x,y = self.cell_array[col][row] 

它给我这个错误:

TypeError: list indices must be integers, not str 

我在做什么错?

+1

检查'col'和'row'值。 – user3 2014-12-03 08:06:41

+1

也许你的索引是字符串而不是整数? – 2014-12-03 08:13:20

+0

难道你不能只读_错误信息吗? – 2014-12-03 09:08:50

回答

3

山口和行类型的类型必须为int

取代:

x,y = self.cell_array[col][row] 

到:

x,y = self.cell_array[int(col)][int(row)]