def has_field(obj, field):
    """Check if an object has a certain attribute, or if a dictionary
    has a certain key.

    :param obj: the data object
    :type obj: object or dict
    :param field: the field name
    :type field: str
    :returns: True if the object has the field, False otherwise
    :rtype: bool
    """
    if isinstance(obj, dict):
        # Object is a dictionary.
        return field in obj
    else:
        # Object is an instance.
        return hasattr(obj, field)