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:
http://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html
Here I am concerned is how attribute matrix.rows is changed. Through pdb
debugging, I can see in line 97, once "self.solutions = 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(self, val):
self.solved = True
self.solutions = set((val,))
self.matrix.changed = True
for other in self.row+self.col+self.submatrix:
if other is self: continue
if other.solutions == self.solutions: raise DeadEnd()
other.delSolutions(self.solutions)
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
--
http://mail.python.org/mailman/listinfo/python-list