Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import failed.
(dotted_path)
| 17 | |
| 18 | |
| 19 | def import_string(dotted_path): |
| 20 | """ |
| 21 | Import a dotted module path and return the attribute/class designated by |
| 22 | the last name in the path. Raise ImportError if the import failed. |
| 23 | """ |
| 24 | try: |
| 25 | module_path, class_name = dotted_path.rsplit(".", 1) |
| 26 | except ValueError as err: |
| 27 | raise ImportError("%s doesn't look like a module path" % dotted_path) from err |
| 28 | |
| 29 | try: |
| 30 | return cached_import(module_path, class_name) |
| 31 | except AttributeError as err: |
| 32 | raise ImportError( |
| 33 | 'Module "%s" does not define a "%s" attribute/class' |
| 34 | % (module_path, class_name) |
| 35 | ) from err |
| 36 | |
| 37 | |
| 38 | def autodiscover_modules(*args, **kwargs): |