- Author:
- joshua
- Posted:
- February 28, 2007
- Language:
- Python
- Version:
- Pre .96
- Score:
- 3 (after 3 ratings)
foo = dynamic_import ( 'rawr.i.am.a.lion' )
Will import lion from 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)
|
More like this
- Form field with fixed value by roam 1 week, 5 days ago
- New Snippet! by Antoliny0919 2 weeks, 4 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 6 months, 4 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Looks great for plugins!
#
Please login first before commenting.