Standard Library

CSV

The csv module handles comma-separated values following RFC 4180: quoted fields, embedded commas, newlines in quoted fields, and escaped quotes (doubled).

from csv import parse_records, write_records

let text = "name,age\nAlice,30\nBob,25"
let records = parse_records(text)
print(records[0]["name"])    # Alice

let output = write_records(records, ["name", "age"])

Functions

FunctionReturnsDescription
parse_rows(text)List[List[Str]]Parse CSV text into a list of rows
parse_records(text)List[Dict[Str, Str]]Parse CSV with headers, first row becomes keys
write_rows(rows)StrSerialize rows to CSV text; auto-quotes
write_records(records, headers)StrSerialize records to CSV with given headers
← Text
Logging →