def rec_getattr(obj, attr, default):
    """Get object's attribute. May use dot notation.

    >>> class C(object): pass
    >>> a = C()
    >>> a.b = C()
    >>> a.b.c = 4
    >>> rec_getattr(a, 'b.c')
    4
    """
    if obj is None:
        return default
    else:
        if '.' not in attr:
            return getattr(obj, attr, default)
        else:
            attr, attrs = attr.split('.', 1)
            return rec_getattr(getattr(obj, attr), attrs, default)