繁体   English   中英

AI Python-TypeError:“ int”对象没有属性“ __getitem__”

[英]AI Python - TypeError: 'int' object has no attribute '__getitem__'

在我正在使用的AI代码中,程序必须检查棋盘上的正方形是否为空。 这由一个零的nxn矩阵表示,并且在代码的这一部分中,程序检查当前平方(数组中的坐标)是否为空:

# Check if a square is empty
def square_is_empty(i,j, state):
      if state[i][j] == 0:
         return True
      return False   

但是,我得到一个输出错误,说:

in square_is_empty
    if state[i][j] == 0:
TypeError: 'int' object has no attribute '__getitem__'

尽管阅读了关于同一问题的多个答案,但我仍然没有设法解决我的问题! 谢谢

以某种方式,您传递的state数组本身就是一个int并在[i]元素的访问中触发此错误,或者state数组中包含int ,并且在[j]元素的访问时触发此错误:

您可能应该看一下state变量的方式,并确定为什么它可能包含int而不是list数据类型。 最简单的方法是仅将其打印为print state

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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