By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,362 Members | 1,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,362 IT Pros & Developers. It's quick & easy.

Re: Quesion on class.attributes assignment

P: n/a


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/su...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

Jul 25 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.