I have a class called cell:
class cell:
def __init__(self, row, column, state):
self.x = column * 20
self.y = row * 20
self.state = state
I have a list of cells which I create using nested for loops:
grid = []
for x in range(20):
for y in range(20):
grid.append(cell(x, y, bool(random.getrandbits(1))))
I can append cells to this grid by using cell() with no issues.
Later on, I have a subroutine called CalculateNextGrid() which creates a list of cells and returns it as an output.
def CalculateNextGrid(grid):
output = []
index = 0
row = 0
column = 0
for cell in grid:
print(grid)
neighbors = CountCells(index, grid, 20)
if cell.state == True:
if neighbors < 2 or neighbors > 3:
output.append(cell(row, column, False))
grid.append(cell(x, y, bool(random.getrandbits(1))))
else:
output.append(cell(row, column, True))
else:
if neighbors == 3:
output.append(cell(row, column, True))
else:
output.append(cell(row, column, False))
row += 1
if row == 20:
row = 0
column += 1
return output
When I use output.append() to add cells to the list, python throws a "cell object not callable" error, despite it working in the code earlier on. Why is this?

for cell in grid-- you are using the namecellfor something else. (This is partly the reason you should capitalise class names, e.g.Cell)for c in cells