dynamic inheritance

Dan Sommers me at privacy.net
Thu Jun 8 22:50:42 EDT 2006


On Thu, 08 Jun 2006 21:14:48 -0400,
alf <ask at me> wrote:

> is there any way to tell the class the base class during runtime?

    >>> class A(object):
    >>>     pass
    >>> class B(object):
    >>>     pass
    >>> o = A()
    >>> o.__class__
    <class '__main__.A'>
    >>> o.__class__ = B
    >>> o.__class__
    <class '__main__.B'>

I don't know if that's a good idea.  Maybe this one:

    class A(object):
        pass
    class B(object):
        pass

    if some_function():
        C = A
    else:
        C = B

    class D(C):
        pass

Why do you want to change a class' base class during runtime?

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list