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)

More like this

  1. Humanize lists of strings in templates by ChipX86 6 years ago
  2. Unfuddle-style post-commit emails - tied to a specific Django project. by jsandell 4 years, 9 months ago
  3. Digg Style URL String Parser by addicted 6 years, 2 months ago
  4. Dynamic import from an installed app by Archatas 4 years, 2 months ago
  5. Download images as png or pdf by gkelly 6 years, 2 months ago

Comments

wiz (on March 1, 2007):

Looks great for plugins!

#

(Forgotten your password?)