From: michele.simionato@... Date: 2006-10-06T16:20:10+09:00 Subject: Re: dynamically changing superclass/mixins Michael Keller wrote: > 1. Can I change the superclass for an already defined class? That is, > remove an existing relationship or add a new one? I haven't been able to > figure that out. > > 2. Can I also remove modules that I included into a class? I have only > found a very ugly way to do this: undefine the class (Klass = nil) and > define it anew. I am not sure even, what the effect was on existing > instances; if they adapted the new behaviour or not. Since people mentioned Io, I feel free to post a Python solution: class Base(object): def meth(self): print 'called B.meth' class Mixin1(object): def meth1(self): print 'called meth1' class Mixin2(object): def meth2(self): print 'called meth2' class C(Base, Mixin1): pass c = C() c.meth() c.meth1() C.__bases__ = (Base, Mixin2) # change the base classes (ick!) print [methname for methname in dir(c) if methname.startswith('meth')] c.meth() c.meth2() c.meth1() # this gives an error now Michele Simionato