def get_by_path(d, path):
    """Access an element of the dict d using the (possibly dotted) path.

    For example, 'foo.bar.baz' would return d['foo']['bar']['baz'].

    Args:
        d (dict):
            (nested) dictionary
        path (str):
            path to access the dictionary

    Returns:
        the value corresponding to d[p1][p2]...

    Raises:
        KeyError:
            if any key along the path was not found.
    """
    current_node = d
    for p in path.split('.'):
        try:
            current_node = current_node[p]
        except KeyError:
            raise KeyError(
                'Path "{}" could not be resolved. Key "{}" missing. Available keys are: [{}]'
                .format(path, p, ', '.join(sorted(current_node.keys()))))
    return current_node
