def getattr_str(obj, attr, fmt=None, fallback='?'):
    """Returns a string of the given object's attribute, defaulting to the
    fallback value if attribute is not present."""
    if hasattr(obj, attr):
        if fmt is not None:
            return fmt % getattr(obj, attr)
        return str(getattr(obj, attr))
    return fallback