title: How can I dynamically create derived classes from a base class
body: <p>For example I have a base class as follows: </p>
  
  <pre><code>class BaseClass(object):
      def __init__(self, classtype):
          self._type = classtype
  </code></pre>
  
  <p>From this class I derive several other classes, e.g.</p>
  
  <pre><code>class TestClass(BaseClass):
      def __init__(self):
          super(TestClass, self).__init__('Test')
  
  class SpecialClass(BaseClass):
      def __init__(self):
          super(TestClass, self).__init__('Special')
  </code></pre>
  
  <p>Is there a nice, pythonic way to create those classes dynamically by a function call that puts the new class into my current scope, like:</p>
  
  <pre><code>foo(BaseClass, "My")
  a = MyClass()
  ...
  </code></pre>
  
  <p>As there will be comments and questions why I need this: The derived classes all have the exact same internal structure with the difference, that the constructor takes a number of previously undefined arguments. So, for example, <code>MyClass</code> takes the keywords <code>a</code> while the constructor of class <code>TestClass</code> takes <code>b</code> and <code>c</code>. </p>
  
  <pre><code>inst1 = MyClass(a=4)
  inst2 = MyClass(a=5)
  inst3 = TestClass(b=False, c = "test")
  </code></pre>
  
  <p>But they should NEVER use the type of the class as input argument like</p>
  
  <pre><code>inst1 = BaseClass(classtype = "My", a=4)
  </code></pre>
  
  <p>I got this to work but would prefer the other way, i.e. dynamically created class objects. </p>