我想将一个列表附加到另一个列表中,但它给了我错误:
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()
答案 0 :(得分:2)
append不返回对象。所以你为变量free分配了None。