def setattrdefault(obj, attribute, default=None):
    """Setdefault for attribute.

    Returns 'attribute' value if defined or set it to default and return it.
    """
    try:
        return getattr(obj, attribute)
    except AttributeError:
        setattr(obj, attribute, default)
        return default
