[Tutor] Mixing in and Mixing out classes in python

Tomaz Bevec tomazbevec at yahoo.com
Thu Jul 31 12:39:46 CEST 2008


Hello,

I am using the following function to mixin in classes into specific object instances (this is adapted from python-list written py J.Jacob "new-style-classes-mixin", Fri Aug 9 14:05:41 CEST 2002):

***************************************************************************
def doMixin(targetInstance, extraClass):
    """
    Mixin new style classes see thread python tutor list, 
    appends the given name                                                                         onto the class name
    """
    class NewClass(extraClass,targetInstance.__class__): pass
      NewClass.__name__=targetInstance.__class__.__name__+"_"+extraClass.__name__
    targetInstance.__class__=NewClass
    try:
        extraClass.initialize(targetInstance)
    except AttributeError:
        pass
***************************************************************************

Is there an analogous way to "Mixout" classes from an instance at runtime?

Thank you,
Tomaz


      


More information about the Tutor mailing list