Dynamic class creation - Python
<p>Here is the scenario:</p>

<p>I have two classes:</p>

<pre><code>class A:
  pass:

class B:
  pass
</code></pre>

<p>Now I want to create a client, in that I need to have a small utility method, which should return my class template/object e.g: class A, class B, as I pass on the class name to that utility e.g <code>get_obj(classA)</code>.</p>

<p>Now, is this possible? If then please suggest an approach, as I don't get any correct answer as of now in web.</p>

<p>Hope I am making sense.</p>

<p>Standard library function <a href="https://docs.python.org/3/library/collections.html#collections.namedtuple" rel="nofollow"><code>namedtuple</code></a> creates and returns a class. Internally it uses <code>exec</code>. It may be an inspiration for what you need.</p>

<p>Source code: <a href="https://github.com/python/cpython/blob/master/Lib/collections/__init__.py#L356" rel="nofollow">https://github.com/python/cpython/blob/master/Lib/collections/<strong>init</strong>.py#L356</a></p>

python oop inheritance