Dynamic Importing in Python (Dotted statments)
<p>I'm having trouble with the following code:</p>

<pre><code>def get_module(mod_path):
    mod_list = mod_path.split('.')
    mod = __import__(mod_list.pop(0))

    while mod_list:
        mod = getattr(mod, mod_list.pop(0))

    return mod
</code></pre>

<p>When I do <code>get_module('qmbpmn.common.db_parsers')</code> I get the error message:
<code>AttributeError: 'module' object has no attribute 'db_parsers'</code>.</p>

<p>However: <code>import qmbpmn.common.db_parsers</code> works perfectly fine.</p>
