title: How can I conditionally add in a mixin to the current class on instantiation?
body: <p>I'd like to have a class that adds in mixins based on arguments passed to the constructor. This is what I've tried:</p>
  
  <pre><code>class MixinOne(object):
      def print_name(self):
          print("{} is using MixinOne.".format(self.name))
  
  
  class MixinTwo(object):
      def print_name(self):
          print("{} is using MixinTwo.".format(self.name))
  
  
  class Sub(object):
  
      def __new__(cls, *args, **kwargs):
  
          mixin = args[1]
  
          if mixin == 'one':
              bases = (MixinOne,) + cls.__bases__
          elif mixin == 'two':
              bases = (MixinTwo,) + cls.__bases__
  
          return object.__new__(type('Sub', bases, dict(cls.__dict__)))
  
      def __init__(self, name, mixin):
  
          print('In Sub.__init__')
  
          self.name = name
  </code></pre>
  
  <p>The only problem with this seems to be that <code>__init__</code> doesn't get called, so the <code>print_name</code> methods will not work.</p>
  
  <ol>
  <li>How do I get <code>__init__</code> on <code>Sub</code> to fire?</li>
  </ol>
  
  <p>or</p>
  
  <ol start="2">
  <li>Is there a better way to do this?</li>
  </ol>