(
    data: Iterable[Dict[str, Any]] | Iterable[Iterable],
    filepath: types.PathLike,
    *,
    encoding: Optional[str] = None,
    make_dirs: bool = False,
    fieldnames: Optional[Sequence[str]] = None,
    dialect: str = "excel",
    delimiter: str = ",",
    quoting: int = csv.QUOTE_NONNUMERIC,
)
Write rows of ``data`` to disk at ``filepath``, where each row is an iterable
    or a dictionary of strings and/or numbers, written to one line with values
    separated by ``delimiter``.

    Args:
        data: If ``fieldnames`` is None, an iterable of iterables of strings
            and/or numbers to write to disk; for example::

                [['That was a great movie!', 0.9],
                 ['The movie was okay, I guess.', 0.2],
                 ['Worst. Movie. Ever.', -1.0]]

            If ``fieldnames`` is specified, an iterable of dictionaries with
            string and/or number values to write to disk; for example::

                [{'text': 'That was a great movie!', 'score': 0.9},
                 {'text': 'The movie was okay, I guess.', 'score': 0.2},
                 {'text': 'Worst. Movie. Ever.', 'score': -1.0}]

        filepath: Path to file on disk to which data will be written.
        encoding: Name of the encoding used to decode or encode the data in ``filepath``.
        make_dirs: If True, automatically create (sub)directories if not already present
            in order to write ``filepath``.
        fieldnames: Sequence of keys that identify the order in which
            values in each rows' dictionary is written to ``filepath``. These are
            included in ``filepath`` as a header row of column names.

            .. note:: Only specify this if ``data`` is an iterable of dictionaries.

        dialect: Grouping of formatting parameters that determine how
            the data is parsed when reading/writing.
        delimiter: 1-character string used to separate fields in a row.
        quoting: Type of quoting to apply to field values. See:
            https://docs.python.org/3/library/csv.html#csv.QUOTE_NONNUMERIC

    See Also:
        https://docs.python.org/3/library/csv.html#csv.writer
Write rows of ``data`` to disk at ``filepath``, where each row is an iterable
    or a dictionary of strings and/or numbers, written to one line with values
    separated by ``delimiter``.
Write rows of data to disk at filepath where each row is an iterable or a dictionary of strings and / or numbers written to one line with values separated by delimiter .
def write_csv(
    data: Iterable[Dict[str, Any]] | Iterable[Iterable],
    filepath: types.PathLike,
    *,
    encoding: Optional[str] = None,
    make_dirs: bool = False,
    fieldnames: Optional[Sequence[str]] = None,
    dialect: str = "excel",
    delimiter: str = ",",
    quoting: int = csv.QUOTE_NONNUMERIC,
) -> None:
    """
    Write rows of ``data`` to disk at ``filepath``, where each row is an iterable
    or a dictionary of strings and/or numbers, written to one line with values
    separated by ``delimiter``.

    Args:
        data: If ``fieldnames`` is None, an iterable of iterables of strings
            and/or numbers to write to disk; for example::

                [['That was a great movie!', 0.9],
                 ['The movie was okay, I guess.', 0.2],
                 ['Worst. Movie. Ever.', -1.0]]

            If ``fieldnames`` is specified, an iterable of dictionaries with
            string and/or number values to write to disk; for example::

                [{'text': 'That was a great movie!', 'score': 0.9},
                 {'text': 'The movie was okay, I guess.', 'score': 0.2},
                 {'text': 'Worst. Movie. Ever.', 'score': -1.0}]

        filepath: Path to file on disk to which data will be written.
        encoding: Name of the encoding used to decode or encode the data in ``filepath``.
        make_dirs: If True, automatically create (sub)directories if not already present
            in order to write ``filepath``.
        fieldnames: Sequence of keys that identify the order in which
            values in each rows' dictionary is written to ``filepath``. These are
            included in ``filepath`` as a header row of column names.

            .. note:: Only specify this if ``data`` is an iterable of dictionaries.

        dialect: Grouping of formatting parameters that determine how
            the data is parsed when reading/writing.
        delimiter: 1-character string used to separate fields in a row.
        quoting: Type of quoting to apply to field values. See:
            https://docs.python.org/3/library/csv.html#csv.QUOTE_NONNUMERIC

    See Also:
        https://docs.python.org/3/library/csv.html#csv.writer
    """
    with io_utils.open_sesame(
        filepath, mode="wt", newline="", encoding=encoding, make_dirs=make_dirs
    ) as f:
        csv_writer: Union[csv.DictWriter, Any]
        if fieldnames:
            csv_writer = csv.DictWriter(
                f, fieldnames, dialect=dialect, delimiter=delimiter, quoting=quoting,
            )
            csv_writer.writeheader()
        else:
            csv_writer = csv.writer(
                f, dialect=dialect, delimiter=delimiter, quoting=quoting,
            )
        csv_writer.writerows(data)
def write_csv ( data : Iterable [ Dict [ str , Any ] ] | Iterable [ Iterable ] , filepath : types . PathLike , * , encoding : Optional [ str ] = None , make_dirs : bool = False , fieldnames : Optional [ Sequence [ str ] ] = None , dialect : str = "excel" , delimiter : str = "," , quoting : int = csv . QUOTE_NONNUMERIC , ) -> None : with io_utils . open_sesame ( filepath , mode = "wt" , newline = "" , encoding = encoding , make_dirs = make_dirs ) as f : csv_writer : Union [ csv . DictWriter , Any ] if fieldnames : csv_writer = csv . DictWriter ( f , fieldnames , dialect = dialect , delimiter = delimiter , quoting = quoting , ) csv_writer . writeheader ( ) else : csv_writer = csv . writer ( f , dialect = dialect , delimiter = delimiter , quoting = quoting , ) csv_writer . writerows ( data )