Reputation: 27
I want to append a list into another list, but it gives me the error:
AttributeError: 'NoneType' object has no attribute 'append'
Originally I wanted to append the list to an array, but that also didn't work...
Here's my code:
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()
Upvotes: 0
Views: 2759
Reputation: 253
append doesn't return an object. So you assigned None to the variable free.
Upvotes: 2