Re: Assigning to __class__ attribute

2010-12-03 Thread Steven D'Aprano
On Fri, 03 Dec 2010 19:28:00 +, kj wrote: > This was the first surprise for me: assigning to the __class__ attribute > not only isn't vetoed, but in fact changes the instances class: > > Oh-ky... > > First question: how kosher is this sort of class transmutation through > assignment to _

Re: Assigning to __class__ attribute

2010-12-03 Thread Mark Wooding
kj writes: > >>> class Spam(object): pass > > Now I define an instance of Spam and an instance of Spam's superclass: > >>> x = Spam() > >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) There's the `__bases__' attribute, which is simply a tuple of the class's direct su

Re: Assigning to __class__ attribute

2010-12-03 Thread Arnaud Delobelle
kj writes: > I have a couple of questions regarding assigning to an instance's > __class__ attribute. > > The first is illustrated by the following interaction. First I > define an empty class: > class Spam(object): pass > ... > > Now I define an instance of Spam and an instance of Spam's

Re: Assigning to __class__ attribute

2010-12-03 Thread Robert Kern
On 12/3/10 1:28 PM, kj wrote: I have a couple of questions regarding assigning to an instance's __class__ attribute. The first is illustrated by the following interaction. First I define an empty class: class Spam(object): pass ... Now I define an instance of Spam and an instance of Spam'

Assigning to __class__ attribute

2010-12-03 Thread kj
I have a couple of questions regarding assigning to an instance's __class__ attribute. The first is illustrated by the following interaction. First I define an empty class: >>> class Spam(object): pass ... Now I define an instance of Spam and an instance of Spam's superclass: >>> x = Spam()