Dynamically Import a Module (and return it)

1
2
3
4
5
def dynamic_import( path ):
    l = path.rfind('.')
    parent, child = path[:l], path[l+1:]
    base = __import__(parent, globals(), globals(), [child])
    return getattr(base, child, None)

Comments

wiz (on March 1, 2007):

Looks great for plugins!

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.