def import_attribute(name):
    """
    Import attribute using string reference.
    Example:
    import_attribute('a.b.c.foo')
    Throws ImportError or AttributeError if module or attribute do not exist.
    """
    i = name.rfind('.')

    module, attr = name[:i], name[i+1:]
    mod = __import__(module, globals(), locals(), [attr])

    return getattr(mod, attr)