def apply_to_field_if_exists ( effect , field_name , fn , default ) : value = getattr ( effect , field_name , None ) if value is None : return default else : return fn ( value )
python fallback on not found values
Apply function to specified field of effect if it is not None otherwise return default .
def apply_to_field_if_exists(effect, field_name, fn, default):
    """
    Apply function to specified field of effect if it is not None,
    otherwise return default.
    """
    value = getattr(effect, field_name, None)
    if value is None:
        return default
    else:
        return fn(value)