def export(self, file_or_path): """Export the data of this instance to ``file_or_path``. :param file_or_path: Either a file path (in this case the data is written to a file at this location) or a file object (in this case the data is written to its .write() function). """ def write_data(out_file): self._file = out_file self._doc_start() self._write_header() self._write_body() self._doc_end() _misc.write_to_file_or_path(file_or_path, write_data)
def export(self, file_or_path): """Export the data of this instance to ``file_or_path``. :param file_or_path: Either a file path (in this case the data is written to a file at this location) or a file object (in this case the data is written to its .write() function). """ def write_data(out_file): self._file = out_file self._doc_start() self._write_header() self._write_body() self._doc_end() _misc.write_to_file_or_path(file_or_path, write_data)
def _csv_dict_writer(file_or_path, ordered_lefts: list, data: list): """ Writes a CSV file using csv.DictWriter. Relies on the header names and dictionary of rows of dictionaries that map values to a header :param file_or_path: Either a file path (in this case the CSV data is written to a file at this location) or a file object (in this case the CSV data is written to its .write() function). :param ordered_lefts: Header values. :param data: List of rows, where each element is a dictionary mapping to the fieldname header values. """ def write_data(out_file): writer = _csv.DictWriter( f=out_file, fieldnames=ordered_lefts, dialect='excel') writer.writeheader() for row in data: writer.writerow(row) _misc.write_to_file_or_path(file_or_path, write_data)
def _csv_dict_writer(file_or_path, ordered_columns: _collections.Sequence, data: _collections.Sequence): """Write a CSV file using `csv.DictWriter`. :param file_or_path: Either a file path (in this case the CSV data is written to a file at this location) or a file object (in this case the CSV data is written to its ``.write()`` function). :param ordered_columns: A `Sequence` of column names (atoms). The columns are written in the given order. :param data: A `Sequence` of rows, where each row is a dictionary, mapping a column name to its value in the given row. Both the column name and the value are atoms. """ def write_data(out_file): writer = _csv.DictWriter( f=out_file, fieldnames=ordered_columns, dialect='excel') writer.writeheader() for row in data: writer.writerow(row) _misc.write_to_file_or_path(file_or_path, write_data)
def _csv_dict_writer(file_or_path, ordered_columns: _collections.Sequence, data: _collections.Sequence): """Write a CSV file using `csv.DictWriter`. :param file_or_path: Either a file path (in this case the CSV data is written to a file at this location) or a file object (in this case the CSV data is written to its ``.write()`` function). :param ordered_columns: A `Sequence` of column names (atoms). The columns are written in the given order. :param data: A `Sequence` of rows, where each row is a dictionary, mapping a column name to its value in the given row. Both the column name and the value are atoms. """ def write_data(out_file): writer = _csv.DictWriter( f=out_file, fieldnames=ordered_columns, dialect='excel') writer.writeheader() for row in data: writer.writerow(row) _misc.write_to_file_or_path(file_or_path, write_data)