object vs class oriented -- xotcl

William Pursell bill.pursell at gmail.com
Tue Jan 29 13:22:24 EST 2008


On Jan 24, 9:16 pm, "Guilherme Polo" <ggp... at gmail.com> wrote:
> 2008/1/24, William Pursell <bill.purs... at gmail.com>:
>  <referring to changing an objects class>
>  Can I do it in Python?
>
>
> class A(object): pass
> class B(object): pass
>
> a = A()
> a.__class__ = B
>
> That ? Maybe you meant something else.

That is what I was referring to, but it isn't the core
functionality that I'm after.  (My bad for a poor
description.)

I'm fairly excited at the idea of being able to
do per-object mixins in xotcl.  I guess it would
look like this in python:

BROKEN CODE:
a = object()
a.__class__.append( foo )
a.__class__.append( bar )

In python, if you want an object to me a member
of 2 classes, it seems that you have no choice but
to declare a new class that inherits from both.  eg:

class foobar( foo, bar):
  pass
a = foobar()

Is it possible to make an object be a member
of 2 classes without defining such a class?  I
believe "per object mixin" is the correct
term for such an animal.  The first several google
hits on that phrase all reference xotcl, so I'm
not sure if that is an xotcl inspired vocabulary
that isn't really standard.



More information about the Python-list mailing list