def import_from_path(path):
    """
    Imports a package, module or attribute from path
    Thanks http://stackoverflow.com/a/14050282/1267398

    >>> import_from_path('os.path')
    <module 'posixpath' ...
    >>> import_from_path('os.path.basename')
    <function basename at ...
    >>> import_from_path('os')
    <module 'os' from ...
    >>> import_from_path('getrektcunt')
    Traceback (most recent call last):
    ImportError:
    >>> import_from_path('os.dummyfunc')
    Traceback (most recent call last):
    ImportError:
    >>> import_from_path('os.dummyfunc.dummylol')
    Traceback (most recent call last):
    ImportError:
    """
    try:
        return importlib.import_module(path)
    except ImportError:
        if '.' not in path:
            raise
        module_name, attr_name = path.rsplit('.', 1)
        if not does_module_exist(module_name):
            raise ImportError("No object found at '{}'".format(path))
        mod = importlib.import_module(module_name)

        if not hasattr(mod, attr_name):
            raise ImportError("No object found at '{}'".format(path))
        return getattr(mod, attr_name)
Imports a package, module or attribute from path
    Thanks http://stackoverflow.com/a/14050282/1267398

    >>> import_from_path('os.path')
    <module 'posixpath' ...
    >>> import_from_path('os.path.basename')
    <function basename at ...
    >>> import_from_path('os')
    <module 'os' from ...
    >>> import_from_path('getrektcunt')
    Traceback (most recent call last):
    ImportError:
    >>> import_from_path('os.dummyfunc')
    Traceback (most recent call last):
    ImportError:
    >>> import_from_path('os.dummyfunc.dummylol')
    Traceback (most recent call last):
    ImportError: