TypeError:列表索引必须是整数,而不是str(MAPNIK)

2024-09-30 02:25:07 发布

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

我正在编写一个函数来计算到道路上某些点的最短路径,而不是像乌鸦一样飞来飞去,但是我不断得到错误:

Traceback (most recent call last): File "P:\understandinggis\assessment2\Assessment2.py", line 177, in if shortestPath1(g, line) <= maxDist: File "P:\understandinggis\assessment2\Assessment2.py", line 14, in shortestPath1 azF,azB,distance = g.inv(line["coordinates"][l][0], line["coordinates"][l][1], lines["coordinates"][l+1][0], line["coordinates"][l+1][1]) TypeError: list indices must be integers, not str

这是它所指的代码行:

def shortestPath1 (g, line):
        #initialise cumulativelength
        cumulativeLength = 0
        for l in range(len(line)-1):
                azF,azB,distance = g.inv(line['coordinates'][l][0], line['coordinates'][l][1], lines['coordinates'][l+1][0], line['coordinates'][l+1][1])
                cumulativeLength += distance
                return cumulativeLength

Tags: inpylinefiledistancelinescoordinatesinv

热门问题