- February 28, 2007
- Pre .96
- 3 (after 3 ratings)
foo = dynamic_import ( 'rawr.i.am.a.lion' )
rawr.i.am.a and return it. (This isn't really Django specific)
Props to Crast for the original.
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)