Re: Quesion on class.attributes assignment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry Reedy

    Re: Quesion on class.attributes assignment



    John Hanks wrote:
    Hi,
    >
    I am reading a python program now but I just cannot understand how the
    values of class attributes are assigned and changed. Here is the
    original code url:
    A few months ago, my wife gave me a book with sudoku puzzles. After solving a couple by hand, I decided that it was much more fun to try and...

    Here I am concerned is how attribute matrix.rows is changed. Through pdb
    debugging, I can see in line 97, once "self.solut ions = set((val,))" is
    executed, cell.row and matrix.rows will be updated. But I did not see
    any assignment codes here. How could this change happen then? Thanks a lot!
    Newsreaders do not typically have line counters. I presume you are
    referring to
    def setSolution(sel f, val):
    self.solved = True
    self.solutions = set((val,))
    self.matrix.cha nged = True
    for other in self.row+self.c ol+self.submatr ix:
    if other is self: continue
    if other.solutions == self.solutions: raise DeadEnd()
    other.delSoluti ons(self.soluti ons)

    First, self is an instance of the class, so these are all instance
    attributes, not class attributes. The difference is important.

    As to your question, the last line mutates (modifies, updates) each
    member of self.row, self.col, and self.submatrix that is not self
    itself. The method delSolutions has the actual target rebindings.

    tjr

Working...