"Emin.shopper Martinian.shopper" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | How do I reassign self to another object?
Exactly the way you give below. |For example, I want something like | | class foo: | def Update(self,other): Self and other are two local names. Self is presumed to be bound to an instance of foo. Other can be bound to anything, even the same thing as self. But presumably, the other object should be at least foo-compatible. | # make this object the same as other or make this object a copy of other 'same as' is a bit ambiguous. 'a copy' slightly less so. | self = other # This won't work. Yes is does. It reassigns the name 'self' to another object, which is what you requested at the top ;-) To copy attributes, you need self.attribute = other.attribute. Also look into the copy module for cloning objects. | What I really want is *this = other in C++ terminology. Strictly speaking, this is meaningless in Python terms (names, collection slots, attributes, and objects). Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list