0

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()
2
  • This is an implementation issue and should be migrated to SO. One of the moderators can do it to prevent duplicate questions. Commented Apr 7, 2014 at 19:37
  • @AdamZuckerman: where it would be closed as a duplicate. Commented Apr 7, 2014 at 19:45

1 Answer 1

2

append doesn't return an object. So you assigned None to the variable free.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!! Just realised that myself. Boy do I feel stupid now XD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.