from typing import Any


def nestedAttributeFromString(root: Any, loc: str) -> Any:
    """return a sub-object. Example::

        >>> nestedAttributeFromString(parent_object, 'foo.bar.spam.bacon')

    returns the object that can be found at parent_object.foo.bar.spam.bacon.
    """
    mods = loc.split('.')
    obj = root
    for m in mods:
        obj = getattr(obj, m)
    return obj