def safe_attribute_compare(this, that, attribute_name):
    """Compares the named attribute on the objects this and that. The
    attribute need not exist on either object.

    Returns True if --
       (a) Neither object has the attribute, OR
       (b) Both objects have the attribute and the value of the attr is equal.
    Returns False if --
       (c) One object has the attribute and the other doesn't, OR
       (d) Both objects have the attribute and the value of the attr differs.
    """
    this_has = hasattr(this, attribute_name)
    that_has = hasattr(that, attribute_name)

    # For starters, both objects must have the attr.
    equal = (this_has == that_has)

    if equal and this_has:
        # Both this and that have the attr. This covers cases (b) and (d).
        equal = (getattr(this, attribute_name) == getattr(that, attribute_name))
    #else:
        # They're not equal or they're both False. In both cases, there's
        # nothing further to be done; equal already holds the correct value.
        # This is cases (a) and (c).

    return equal