Automation · Python Automation
CSV
Cheat sheet · https://pcornel.dk/topic.php?topic=5270
Answer
Python handles CSV with the csv module's DictReader and DictWriter, which map rows to dictionaries using the header, or with pandas for larger analysis.
Remember
- Use csv.DictReader and DictWriter.
- Open files with newline=''.
- Set the encoding explicitly.
First checks
python3 -c 'import csv;print(next(csv.reader(open("f.csv"))))'— read header- csv.DictReader with explicit delimiter — parsing
- Encoding (utf-8-sig for Excel) — correctness
Verify in this order
CSV → csv reader → rows → validation
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5270