Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';int';对象不可下标-不确定如何修复_Python_Syntax - Fatal编程技术网

Python ';int';对象不可下标-不确定如何修复

Python ';int';对象不可下标-不确定如何修复,python,syntax,Python,Syntax,嘿,伙计们,我遇到了一个错误: 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/Win

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

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

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

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

假设maze.listoflist是一个列表列表-即:
maze.listoflist=[…],[…]

您需要像这样对其进行索引:

maze.listoflist[index_X][index_Y] // Correct indexing listoflist
不像你有:

maze.listoflist[index_X[index_Y]]  // Your version
索引X和索引Y都是整数

然而,这并不是你看到的错误

“int”对象不可下标

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

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


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

什么是currentpos?整数?这就解释了为什么当我给它编制索引时它是不可下标的是的。那么我会做什么改变,因为我仍然无法计算它。一般来说,你必须想出另一个逻辑来获得迷宫索引。currentpos是整数还是整数数组?如果是整数数组,请尝试使用currentpos[]的订阅/索引数量不要超过该数量。如果没有更多的代码细节,我将帮不上你的忙。这确实有帮助,我克服了那个错误。
maze.listoflist[index_X[index_Y]]  // Your version