def import_from_string(val, setting_name):
    """
    Attempt to import a class from a string representation.
    """
    try:
        parts = val.split('.')
        module_path, class_name = '.'.join(parts[:-1]), parts[-1]
        module = importlib.import_module(module_path)
        return getattr(module, class_name)
    except (__HOLE__, AttributeError) as e:
        raise ImportError('Could not import {} for API setting {}. {}: {}.'
                          .format(val, setting_name, e.__class__.__name__, e))
dataset/ETHPy150Open ankitpopli1891/django-autotranslate/autotranslate/utils.py/import_from_string