runtime inheritance (e.g. __new__, __metaclass__)

H Jansen h.jansen at fel.tno.nl
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 
documentation.

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

class Base1:
     pass

class Base2:
     pass

class Meta:
     pass

class Good(Meta):
     pass

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?


Thanks

--Henk


-- 
------------------------------------------------------------------------------
The disclaimer that applies to e-mail from
TNO Physics and Electronics Laboratory
can be found on: http://www.tno.nl/disclaimer/email.html
------------------------------------------------------------------------------



More information about the Python-list mailing list