0

我在python中有以下功能:

def find_str(s, m):
    starting_points = find_starting_points(s,m)
    solution = []
    for i in range(0, len(starting_points)):
        position = starting_points[i]
        solution.append([position])
        solution = build_solution(position, s, m, solution)
    return solution
    pass

当我在 ipython 中运行该文件时,出现以下错误:

     55     for i in range(0, len(starting_points)):
     56         position = starting_points[i]
---> 57         solution.append([position])
     58         solution = build_solution(position, s, m, solution)
     59     return solution

AttributeError: 'NoneType' object has no attribute 'append'

为什么我会收到这个错误?

4

1 回答 1

8

您的build_solution函数在某些时候会返回None. 由于您设置solution了此函数的返回,因此您将其设置为无。

除非您显示build_solution.

于 2012-12-22T22:43:24.793 回答