Title: Theory / Unimportant / CS / Programming / Python / Lib / CSV
Tags: computer_to_instruction automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3/library/csv.html

Instruction: reader(
  file,
  dialect = bar
)
Language: Python
Context: csv
Returns: A list of list of string, as in the CSV file file
Assuming: file is opened with newline=''

Instruction: writer(
  file,
  dialect = bar
)
Language: Python
Context: csv
Returns: A writer, which, given a list of string, writes it as a CSV entry in file
Assuming: file is opened with newline=''

Instruction: get_dialect(foo)
Effect: the dialect associated to name foo
Language: Python
Context: csv

Instruction: unregister_dialect(foo)
Language: Python
Context: csv
Returns: Remove dialect associated with name foo

Instruction: list_dialects()
Effect: The list of dialects
Language: Python
Context: csv

Instruction: field_size_limit()
Effect: The maximum field size allowed by the parser
Language: Python
Context: csv

Instruction: field_size_limit(foo)
Effect: The maximum field size allowed by the parser
Language: Python
Context: csv
Returns: Set the maximum field size to foo

Instruction: register_dialect(
  foo,
  dialect,
  **fmtparas
)
Language: Python
Context: csv
Returns: state that name foo refers to dialect with parameters fmtparas

Instruction: Sniffer().sniff(foo,bar=None)
Language: Python
Context: csv
Returns: A dialect in which foo, a sample of the file, is encoded. With potential delimiters being the elements of bar

Instruction: Sniffer().has_header(foo)
Language: Python
Context: csv
Returns: Whether the sample foo of texts seems to contains CSV header before the CSV rows

Instruction: DictReader(
  foo,
  restval=None,
  dialect='excel',
  *args,
  **kwargs
)
Language: Python
Context: csv
Returns: A reader, returning iteratively each rows, as a dictionnary from row name to its value. Row name is assumed to be found in the first line. If there are not enough elements, its value is None. If there are two much elements, they are associated to the key restval.
Other arguments are passed to the CSV opener

Instruction: DictReader(
  foo,
  fieldnames, restval=None,
  dialect='excel',
  *args,
  **kwargs
)
Language: Python
Context: csv
Returns: A reader, returning iteratively each rows, as a dictionnary from fieldnames[i] to the value of the i-th column.
If there are not enough columns, its value are None. If there are two much elements, they are associated to the key restval.
Other arguments are passed to the CSV opener

Instruction: DictWriter(
  foo,
  fieldnames, restval=None,
  extrasaction='raise',
  dialect='excel',
  *args,
  **kwargs
)
Language: Python
Context: csv
Returns: A writer, taking as argument a dictionnary with keys as in fieldnames, and writting its entry in file foo.
Missing keys are replaced by restval.
In case of extrasaction,

Variable: reader.dialect
Meaning: The dialect used by reader
Page: https://docs.python.org/3/library/csv.html
Context: csv
Language: Python
Variables: reader: a csv reader

Variable: reader.line_num
Meaning: Number of lines already read (which may be more than number of record read)
Page: https://docs.python.org/3/library/csv.html
Context: csv
Language: Python
Variables: reader: a csv reader

Variable: reader.fieldnames
Meaning: The field names used by the CSV reader
Page: https://docs.python.org/3/library/csv.html
Context: csv
Language: Python
Variables: reader: a csv reader