Я печатаю значение того, что, как я думал, было списком, но вывод, который я получаю:
[...]
Что это означает? Как я могу проверить это? Я пробовал:
myVar.__repr__() != '[...]'
и
myVar.__repr_() != Ellipsis
но не кости...
Здесь вырезание кода, который дает проблему:
def buildPaths(graph, start, end, path=[], totalPaths=[]):
"""
returns list of all possible paths from start node to the end node
"""
path = path + [start]
if start == end:
return path
for nextNode in graph.childrenOf(start):
if nextNode not in path:
newPath = buildPaths(graph, nextNode, end, path, totalPaths)
if newPath != []: # test
totalPaths.append(newPath)
return totalPaths
totalPaths содержит много [...] предположительно рекурсивных списков, но я не понимаю, почему. Я изменил тест на #test, чтобы предотвратить это.
Я также пробовал:
def buildPaths(graph, thisNode, end, path=[], totalPaths=None):
"""
returns list of all possible paths from start node to the end node
"""
path = path + [thisNode]
if thisNode == end:
return path
for nextNode in graph.childrenOf(thisNode):
if nextNode not in path:
newPath = buildPaths(graph, nextNode, end, path, totalPaths)
if newPath != None:
if totalPaths == None:
totalPaths = [newPath]
else:
totalPaths.append(newPath)
return totalPaths
чтобы явно возвращать None
для пустых путей.