2014-12-03 76 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)]