title: How to call class instances stored in a list of lists?
body: <p>I'm using Python 2.7.6 in Kubuntu 14.04; trying (for my own edification) to implement Conway's Life using a single class instantiated for each cell to do the "cellular automaton" work.  In the process, I'm storing an instance in each member of a list of lists.  The problem is, when I try to call instance methods while I iterate through the indices for the list(s), I get an error: <code>TypeError: 'int' object has no attribute '__getitem__'</code>.  Here's the code I have:</p>
  
  <pre><code># Conway's Life in Python -- initially with text graphics, 50x50, possibly
  # with actual windowing system graphics in a later version.  Use a class
  # replicated in quantity (2500!) for each cell to vastly simplify computation;
  
  # is below worth it or not?  Would bring all four cores into computation.
  # learn how to do threading to let the cells calculate in parallel, but pass
  # signals to keep them in step.
  
  class Cell(object):
  
    def __init__(self, coords, size):
      # coords is a tuple of x, y; size is the field height/width in cells
      self.position = coords
      self.is_live = False
      pass
  
    def count_neighbors(self):
      x,y = self.position
      self.neighbors = 0
      for i in range (-1, 1):
        for j in range (-1, 1):
      # add size and modulo (size - 1) to create wrapped edges
      if field[(x + i + self.xy) % (self.xy - 1)] [(y + j + 
                                    self.xy) % (self.xy - 1)]:
        ++self.neighbors
      pass
  
    def live_or_die (self):
      if self.neighbors &lt; 2 or self.neighbors &gt; 3:
        self.is_live = False
      elif self.neighbors == 3:
        self.is_live = True
      else:
        pass
  
  # main program
  
  extent = 4 #size of field
  
  # create list of lists of Cell objects w/ coord tuples
  # for i in range extent:
  #   for j in range extent:
  #     field[i[j]] = (i,j)
  
  field = [[Cell((i, j), extent) for j in range(extent)] for i in range(extent)]
  
  # insert population setting here
  
  # insert population setting here
  
  for i in range (extent):
    for j in range (extent):
      field[i[j]].count_neighbors()
  
  for i in range (extent):
    for j in range (extent):
      field[i[j]].live_or_die()
  </code></pre>
  
  <p>The last two <code>for</code> loops will be wrapped in a <code>while</code> for continued operation once I've worked out how to create the initial population and stop the program in a controlled way.  Obviously, <code>extent</code> will be set higher once I've got the iteration debugged (50x50 only used about 5.5 MiB RAM prior to adding variables to the methods in <code>Cell</code>, so I should be able to run this at screen size with single pixels in graphics mode, if that won't be too slow -- a couple steps per second is plenty fast for my tastes).</p>
  
  <p>Problem is, I'm not seeing a way to individually call the instances of <code>Cell</code> stored in <code>field</code>.  I <em>think</em> the problem here is how I'm nesting the lists, but they have to be nested, don't they?  The <code>j</code> lists are members of the <code>i</code> list.</p>
  
  <p>Full tracebacK:</p>
  
  <pre><code>Traceback (most recent call last):
    File "PyLife.py", line 51, in &lt;module&gt;
      field[i[j]].count_neighbors()
  TypeError: 'int' object has no attribute '__getitem__'
  </code></pre>