runtime inheritance (e.g. __new__, __metaclass__)

H Jansen h.jansen at
Wed Jul 28 14:09:17 CEST 2004

I try to work out how to use __new__ and metaclass (or __metaclass__) 
mechanisms in order to change the base class at runtime. I haven't been 
successful so far, however, even after also reading most of the relevant 

The most simple representation (an oversimplification indeed) of what 
I'm trying to accomplish is this:

class Base1:

class Base2:

class Meta:

class Good(Meta):

What I want to achieve at runtime is this:

g1 = Good(Base1)  # a Good object with base class Base1
g2 = Good(Base2)  # a Good object with base class Base2

Of course, this oversimplified (pseudo-code) example will not work but 
illustrates most clearly my idea. How can I come closest to realizing 
this by using the above mechanisms?



The disclaimer that applies to e-mail from
TNO Physics and Electronics Laboratory
can be found on:

More information about the Python-list mailing list