Saves the sequence to a csv file. Each element should be an iterable which will be expanded to the elements of each row. :param path: path to write file :param mode: file open mode :param dialect: passed to csv.writer :param fmtparams: passed to csv.
(
self,
path,
mode=WRITE_MODE,
dialect="excel",
compression=None,
newline="",
**fmtparams
)
| 1556 | json.dump(self.to_dict(), output) |
| 1557 | |
| 1558 | def to_csv( |
| 1559 | self, |
| 1560 | path, |
| 1561 | mode=WRITE_MODE, |
| 1562 | dialect="excel", |
| 1563 | compression=None, |
| 1564 | newline="", |
| 1565 | **fmtparams |
| 1566 | ): |
| 1567 | """ |
| 1568 | Saves the sequence to a csv file. Each element should be an iterable which will be expanded |
| 1569 | to the elements of each row. |
| 1570 | |
| 1571 | :param path: path to write file |
| 1572 | :param mode: file open mode |
| 1573 | :param dialect: passed to csv.writer |
| 1574 | :param fmtparams: passed to csv.writer |
| 1575 | """ |
| 1576 | |
| 1577 | if "b" in mode: |
| 1578 | newline = None |
| 1579 | |
| 1580 | with universal_write_open( |
| 1581 | path, mode=mode, compression=compression, newline=newline |
| 1582 | ) as output: |
| 1583 | csv_writer = csv.writer(output, dialect=dialect, **fmtparams) |
| 1584 | for row in self: |
| 1585 | csv_writer.writerow([str(element) for element in row]) |
| 1586 | |
| 1587 | def _to_sqlite3_by_query(self, conn, sql): |
| 1588 | """ |