File size: 648 Bytes
2cf9672
777fd0c
 
2cf9672
eacb67f
777fd0c
2cf9672
777fd0c
 
2cf9672
777fd0c
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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])