def rgetattr(obj, attr):
    """
    Recursively get an attribute from object. Extends getattr method

    :param obj: object
    :param attr: attribute to get
    :return:
    """
    attributes = attr.split('.')
    curr_object = obj
    for attribute in attributes:
        list_indices = []
        splitted = attribute.split('[')
        if not splitted:
            splitted = [attribute]
        curr_object = getattr(curr_object, splitted[0])
        if len(splitted) > 1:
            for i in range(1, len(splitted)):
                list_indices.append(splitted[i].replace(']', '').replace(
                    "'", ''))
        for item in list_indices:
            try:
                curr_object = curr_object[item]
            except (KeyError, TypeError, IndexError):
                curr_object = curr_object[int(item)]
    return curr_object
