def get_nested_attr(obj, attr_name):
    """Same as getattr(obj, attr_name), but allows attr_name to be nested
    e.g. get_nested_attr(obj, "foo.bar") is equivalent to obj.foo.bar"""
    for name_part in attr_name.split('.'):
        if hasattr(obj, name_part):
            obj = getattr(obj, name_part)
        else:
            raise AttributeError("module has no " + name_part + " attribute")

    return obj