Skip to main content

Module pycsv

Module pycsv 

Source
Expand description

csv.writer / csv.DictWriter the way CPython writes them.

Default dialect: , delimiter, " quote doubled on escape, QUOTE_MINIMAL, \r\n line terminator. A field is quoted when it contains the delimiter, the quote character, \r or \n. A row that is a single empty field is written as "" so it is not an empty line.

Values are rendered with Python str() semantics via cell: None → empty, True/False, ints plain, floats by repr.

Functions§

cell
Python str() of a JSON scalar as csv would stringify it.
needs_quotes 🔒
read_dicts
csv.DictReader: the first row names the columns. A short row leaves its missing columns absent (Python’s None); a long row’s extras are dropped; a blank line is skipped.
read_rows
csv.reader on a file opened with newline="": the C state machine from _csv.c, default dialect. Quoted fields may span lines and keep their line endings verbatim; a quote inside an unquoted field is literal; a doubled quote inside a quoted field is one quote. A blank line yields an empty row.
write_dicts
DictWriter(fieldnames=cols): header, then each row’s values in column order. A missing key writes an empty cell (restval=""); extra keys are ignored (extrasaction="ignore").
write_row
Write one row. fields are already stringified.