将列表附加到列表:AttributeError:'NoneType'对象没有属性'append'

时间:2014-04-07 18:48:21

标签: python python-3.x

我想将一个列表附加到另一个列表中,但它给了我错误:

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

最初我想将列表附加到数组中,但这也没有用...

这是我的代码:

import numpy
board = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, 1, 2, 0, 0, 0],
                     [0, 0, 0, 2, 1, 0, 0, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0, 0, 0, 0]])

class AI:
    def __init__(self, board):
        self.board = board

    def flank_search(self):
        free = []
        xcoord = 0
        ycoord = 0
        while 0 <= xcoord and xcoord <= 7 and 0 <= ycoord and ycoord <= 7:
            if self.board[xcoord][ycoord] == 0:
                coord1 = [xcoord, ycoord]
                free = free.append([coord1])
                xcoord += 1
                print free
        return free


flank = AI(board)
flank.flank_search()

1 个答案:

答案 0 :(得分:2)

append不返回对象。所以你为变量free分配了None。