diff options
Diffstat (limited to 'factory/utils.py')
-rw-r--r-- | factory/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/factory/utils.py b/factory/utils.py index c592da4..e7cdf5f 100644 --- a/factory/utils.py +++ b/factory/utils.py @@ -81,3 +81,15 @@ def multi_extract_dict(prefixes, kwargs, pop=True, exclude=()): ['%s%s%s' % (prefix, ATTR_SPLITTER, key) for key in extracted]) return results + + +def import_object(module_name, attribute_name): + """Import an object from its absolute path. + + Example: + >>> import_object('datetime', 'datetime') + <type 'datetime.datetime'> + """ + module = __import__(module_name, {}, {}, [attribute_name], 0) + return getattr(module, attribute_name) + |