Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImproperlyConfigured if something goes wrong.

        def import_by_path(dotted_path, error_prefix=''):
    """
    Import a dotted module path and return the attribute/class designated by the
    last name in the path. Raise ImproperlyConfigured if something goes wrong.
    """
    try:
        module_path, class_name = dotted_path.rsplit('.', 1)
    except ValueError:
        raise ImproperlyConfigured("%s%s doesn't look like a module path" % (
            error_prefix, dotted_path))
    try:
        module = import_module(module_path)
    except ImportError as e:
        msg = '%sError importing module %s: "%s"' % (
            error_prefix, module_path, e)
        six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg),
                    sys.exc_info()[2])
    try:
        attr = getattr(module, class_name)
    except AttributeError:
        raise ImproperlyConfigured('%sModule "%s" does not define a "%s" attribute/class' % (
            error_prefix, module_path, class_name))
    return attr
        


src/d/j/django-comments-xtd-1.3a1/django_comments_xtd/__init__.py   django-comments-xtd(Download)
from django_comments_xtd.conf import settings
try:
    from django.utils.module_loading import import_by_path # Django >= 1.6
except ImportError:
    from django_comments_xtd.compat import import_by_path # Django <= 1.5
 
 
def get_model():
    return import_by_path(settings.COMMENTS_XTD_MODEL)
def get_form():
    return import_by_path(settings.COMMENTS_XTD_FORM_CLASS)
 
VERSION = (1, 3, 0, 'a', 1) # following PEP 440