def write_to_buf(output, filepath_or_buffer=None):
    """
    Write output to a file or buffer. If none is provided, nothing happens.

    Parameters
    ----------
    output : str
        The output to write.
    filepath_or_buffer : str or file handle, default None
        The file or buffer to which to write the output.
    """
    if filepath_or_buffer is None:
        return
    if isinstance(filepath_or_buffer, str):
        f = open(filepath_or_buffer, 'w')
        close_file = True
    else:
        f = filepath_or_buffer
        close_file = False
    try:
        f.write(output)
    finally:
        if close_file:
            f.close()
