def import_class(class_uri):
    """
    Import a class by string 'from.path.module.class'
    """

    parts = class_uri.split('.')
    class_name = parts.pop()
    module_uri = '.'.join(parts)

    try:
        module = import_module(module_uri)
    except ImportError as e:
        # maybe we are still in a module, test going up one level
        try:
            module = import_class(module_uri)
        except Exception:
            # if failure raise the original exception
            raise e

    return getattr(module, class_name)
def import_class ( class_uri ) : parts = class_uri . split ( '.' ) class_name = parts . pop ( ) module_uri = '.' . join ( parts ) try : module = import_module ( module_uri ) except ImportError as e : try : module = import_class ( module_uri ) except Exception : raise e return getattr ( module , class_name )
Import a class by string 'from.path.module.class'