def chomp(str_val, ext="\n"):
    """Chomp a suffix off a string.

    Parameters
    ----------
    str_val : str
        String we want to chomp off a suffix, e.g., ``"foo.log"``, and we want to chomp the file extension.
    ext : str
        The suffix we want to chomp. An error is raised if `str_val` doesn't end in `ext`.

    Returns
    -------
    chomped : str
        Version of `str_val` with `ext` removed from the end.
    """
    n = len(ext)
    assert n > 0

    chomped, ext_ = str_val[:-n], str_val[-n:]
    assert ext == ext_, "%s must end with %s" % (repr(str_val), repr(ext))
    return chomped