“int”对象不可下标不确定如何修复

2024-09-30 01:36:45 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,伙计们,我得到一个错误:

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:

Tags: inpydebugsrcapplinecontentsnot
2条回答

我认为您在这里有一些问题,但只能猜测,除非您共享currentpos中的内容,和/或maze.listof列表. 你知道吗

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

你需要这样索引:

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

不像你有:

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

索引X和索引Y都是整数。你知道吗

然而,这不是你看到的错误。你知道吗

'int' object is not subscriptable

告诉我们您有一个int,但正在尝试索引到它。可下标对象是数组、元组、dict和字符串,或者实现getitem()接口的自定义对象,索引到这些对象的语法是使用[]

您认为是列表(或其他可下标类型)的东西不是,而是int

在抛出错误的行之前添加一个print语句,并向我们显示currentpos的内容(这比maze.listof列表). 你知道吗

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

相关问题 更多 >

    热门问题