On Thu, Sep 20, 2012 at 12:57 PM, eryksun <eryk...@gmail.com> wrote: > > I forgot the obligatory warning about class variables. The subclass > gets a shallow copy of the parent class namespace. The in-place ^^^^^^^^^^^^^^^^^^^ > >>> Y.data += [1] > >>> X.data # modified parent, too > [1] > >>> Y.data = Y.data + [2] # creates new list
To clarify, it's not an actual dict.copy in the subclass. In fact, the atrribute is initially only in the parent __dict__, where it's found by object.__getattribute__. In the 2nd example, Y.data on the right-hand side is actually found in the parent class X, then the expression creates a new list which is stored back to Y. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor