我遇到了错误RuntimeError: maximum recursion depth exceeded in cmp
使用列表时。更确切地说,p0 in points
, the points.index(p0)
方法调用以及points.remove(p0)
方法调用points
列表已引发特定字典的错误p0
在我的特定索引处points
列表。这points
发生错误时,列表包含 4700 个字典,从 12000 个对象的列表中将一个字典减少了一个,直到引发错误。这p0
字典包含对列表中另一个字典的引用,该字典在返回中包含对p0
目的。这p0
字典以及它包含的引用在字典中出现两次points
列出三个方法调用中的任何一个引发错误之前的列表。
这个错误从何而来?
EDIT:这是引发错误的代码。
for roadType in roadTypes:
points = roadPoints[roadType][:]
while len(roadTails[roadType]) > 0:
p0 = roadTails[roadType].pop()
p1 = p0['next']
points.remove(p0) # Where the error occurs
points.remove(p1)
while True:
p2 = find(p1, points, 0.01)
if p2:
points.remove(p2)
p3 = p2['next']
points.remove(p3)
if p3 in roadTails[roadType]:
roadTails[roadType].remove(p3)
break
else:
p0, p1 = p2, p3
continue
else: break
这是定义find
, where dist
计算两点之间的距离。
def find(p1, points, tolerance = 0.01):
for p2 in points:
if dist(p2['coords'], p1['coords']) <= tolerance:
return p2
return False
这是错误的完整回溯:
Traceback (most recent call last):
File "app.py", line 314, in <module>
points.remove(p0) # Where the error occurs
RuntimeError: maximum recursion depth exceeded in cmp