import importlib


def _load_symbol(name):
    """Load a symbol by name.

    :param str name: The name to load, specified by `module.attr`.
    :returns: The attribute value. If the specified module does not contain
              the requested attribute then `None` is returned.
    """
    module_name, key = name.rsplit('.', 1)
    try:
        module = importlib.import_module(module_name)
    except ImportError as err:
        # it's possible the symbol is a class method
        module_name, class_name = module_name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        cls = getattr(module, class_name, None)
        if cls:
            attr = getattr(cls, key, None)
        else:
            raise err
    else:
        attr = getattr(module, key, None)
    if not callable(attr):
        raise ValueError('%s is not callable (was %r)' % (name, attr))
    return attr