On Fri, Aug 28, 2009 at 1:27 PM, Miles Kaufmann <span dir="ltr"><<a href="mailto:milesck@umich.edu">milesck@umich.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You're right, of course.  If I had been thinking properly, I would have posted this:<br>
<br>
... the suite namespace and the class namespace would get out of sync when different objects were assigned to the class namespace:</blockquote><div><br>I'm not an expert on Python, but could you define "out of sync" for me? When you call the class as a new instance and assign it to a new variable, the class attributes (self.x) are independent for each instance. The static variables in the class (x, or C.x in this case) is shared between all instances of this class. <br>
</div><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
   # In a hypothetical Python with nested class suite scoping:</blockquote><div><br>Class already provides some kind of scoping/namespace, that is the locals() method for the class. What is pypothetical about this, if you could elaborate? <br>
<br><snips the code><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
With your example, the result is at least easily explainable: self.x is originally 1</blockquote><div><br>Incorrect. "self.x" (or cls.x in your sample code) doesn't exist until you called o.x = 2, which sets "cls.x = 2".<br>
<br>Don't be confused between static variables that are initialised at class creation, and the class attributes which usually is declared inside the __init__ method.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
because the object namespace inherits from the class namespace, but running 'o.x = 2' rebinds 'x' in the object namespace (without affecting the class namespace).  </blockquote><div><br>See above comment.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">It's a distinction that sometimes trips up newbies (and me, apparently ;) ), but it's straightforward to comprehend once explained.  But the distinction between the class suite namespace and the class namespace is far more subtle; extending the lifetime of the first so that it still exists after the second is created is, IMO, asking for trouble (and trying to unify the two double so).</blockquote>
<div><br>It is. I had trouble getting it also, but once I think of all the variables outside of the __init__() method as "static", and the ones within as "class attributes", everything clears out just fine. =]<br>
<br>Any corrections appreciated. I'm merely posting my understanding of Python.<br><br>Cheers,<br>- Xav<br></div></div>