简体   繁体   中英

Can't access tuple inside 2d array python

I have a 2d array that looks much like this:

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

I am trying to access the values of a tuple from a given cell like this:

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

It gives me this error:

TypeError: list indices must be integers, not str

What am I doing wrong?

Type of col and row must be type int

replace:

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

to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM