Search code examples
pythoncursespython-curses

How can I access a position on screen in Curses?


I'm trying to program Conway's game of life on Python, without using classes or the self. thing. I'm really new to curses, and I want to make a condition like:

if screen[y][x] == '*':
     neighbour_count+=1

Where y and x are the coordinates on the screen and I check to see how many neighbours a cell has. I keep getting 'object not suscriptable', and I really don't know how to make that condition work.


Solution

  • You can do this via the inch() or instr() functions. But, you probably shouldn't. Instead, keep copies of the "board" in appropriate structures (one for the current generation, and one for the next), calculate with those, and update the screen each generation.