circuitpython_csv
¶
CircuitPython helper library for working with CSV files
Author(s): Alec Delaney
Implementation Notes¶
Hardware:
None
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- class circuitpython_csv.DictReader(f: TextIOWrapper, fieldnames: Optional[Sequence[str]] = None, restkey: Optional[str] = None, restval: Optional[Any] = None, **kwargs)¶
CSV reader that maps rows to a dict according to given or inferred fieldnames, it also accepts the delimiter and quotechar keywords
- Parameters:
f (io.TextIOWrapper) – The open file to read from
fieldnames (Sequence[str]) – (Optional) The fieldnames for each of the columns, if none is given, it will default to the whatever is in the first row of the CSV file
restkey (str) – (Optional) A key name for values that have no key (row is larger than the length of fieldnames), default is None
restval (Any) – (Optional) A default value for keys that have no values (row is small than the length of fieldnames, default is None
- class circuitpython_csv.DictWriter(f: TextIOWrapper, fieldnames: Sequence[str], restval: str = '', extrasaction: str = 'raise', **kwargs)¶
CSV writer that uses a dict to write the rows according fieldnames, it also accepts the delimiter and quotechar keywords
- Parameters:
f (io.TextIOWrapper) – The open file to write to
fieldnames (Sequence[str]) – The fieldnames for each of the comlumns
restval (str) – A default value for keys that have no values
extrasaction (str) – The action to perform if a key is encountered when parsing the dict that is not included in the fieldnames parameter, either “raise” or “ignore”. Ignore raises a ValueError, and “ignore” simply ignore that key/value pair. Default behavior is “raise”
- class circuitpython_csv.reader(csvfile: TextIOWrapper, delimiter: str = ',', quotechar: str = '"')¶
Basic CSV reader class that behaves like CPython’s
csv.reader()
- Parameters:
csvfile (io.TextIOWrapper) – The open file to read from
delimiter (str) – (Optional) The CSV delimiter, default is comma (,)
quotechar (str) – (Optional) The CSV quote character for encapsulating special characters including the delimiter, default is double quotation mark (“)
- class circuitpython_csv.writer(csvfile: TextIOWrapper, delimiter: str = ',', quoterchar: str = '"')¶
Basic CSV writer class that behaves like CPython’s
csv.writer()
- Parameters:
csvfile (io.TextIOWrapper) – The open CSVfile to write to
delimiter (str) – (Optional) The CSV delimiter, default is comma (,)
quotechar (str) – (Optional) The CSV quote character for encapsulating special characters including the delimiter, default is double quotation mark (“)