'int' 对象不可订阅 - 不确定如何修复

'int' object is not subscriptable - not sure how to fix

大家好,我收到了这个错误:

Traceback (most recent call last):
  File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 1, in <module>
    # Used internally for debug sandbox under external interpreter
  File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 25, in solveMaze
  File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 39, in recursiveSolver
builtins.TypeError: 'int' object is not subscriptable

关于这行代码,我不确定如何修正任何想法?

elif maze.listoflist[currentpos[0][currentpos[1]+1]] == " " and
maze.listoflist[currentpos[0][currentpos[1]+2]] == "*" and [currentpos[0]
[currentpos[1]+2]] not in blacklist:

我猜 currentpos 是一个整数数组,你不能下标(用括号括起来)一个整数。

我认为你这里有一些问题,但只能猜测,除非你分享 currentpos 中的内容,and/or maze.listoflist。

假设 maze.listoflist 是列表的列表 - 即:maze.listoflist = [[...], [...]]

你需要像这样索引:

maze.listoflist[index_X][index_Y] // Correct indexing listoflist

不像你有:

maze.listoflist[index_X[index_Y]]  // Your version

index_X 和 index_Y 都是整数。

但这不是您看到的错误。

'int' object is not subscriptable

告诉我们您有一个 int,但正在尝试对其进行索引。可订阅对象是数组、元组、字典和字符串,或实现 getitem() 接口的自定义对象,索引它们的语法是使用 [ ]

你认为是列表(或其他可订阅类型)的东西不是,它是一个 int。

在抛出错误的行前添加打印语句,并向我们显示currentpos的内容(比maze.listoflist更有可能)。