Export data to a CSV file. :param data: List of dictionaries containing the data to export :param filename: Name of the file to save the CSV data
(data: List[Dict[str, Any]], filename: str)
| 26 | |
| 27 | |
| 28 | def export_to_csv(data: List[Dict[str, Any]], filename: str) -> None: |
| 29 | """ |
| 30 | Export data to a CSV file. |
| 31 | |
| 32 | :param data: List of dictionaries containing the data to export |
| 33 | :param filename: Name of the file to save the CSV data |
| 34 | """ |
| 35 | if not data: |
| 36 | logger.warning("No data to export") |
| 37 | return |
| 38 | |
| 39 | keys = data[0].keys() |
| 40 | with open(filename, "w", newline="", encoding="utf-8") as f: |
| 41 | writer = csv.DictWriter(f, fieldnames=keys) |
| 42 | writer.writeheader() |
| 43 | writer.writerows(data) |
| 44 | logger.info("Data exported to %s", filename) |
| 45 | |
| 46 | |
| 47 | def export_to_xml( |