IR_PR_PilotPro / export /qa_csv.py
Corin1998's picture
Update export/qa_csv.py
777fd0c verified
raw
history blame contribute delete
648 Bytes
# export/qa_csv.py
from __future__ import annotations
from typing import List, Dict, Tuple
import csv, os
def save_qa_csv(qa_list: List[Dict], links: List[str], path: str) -> None:
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8-sig", newline="") as f:
w = csv.writer(f, quoting=csv.QUOTE_ALL)
w.writerow(["Q", "A"])
for item in qa_list:
q = item.get("q") or item.get("Q") or ""
a = item.get("a") or item.get("A") or ""
# 改行はCSV内に残してExcelでも読めるようにする(QUOTE_ALLで安全)
w.writerow([q, a])