Writer

class csv_reader.Writer.CSVDictWriter(name: str, fields: list, mode: str = 'a')

Bases: contextlib.AbstractContextManager

a csv writer class for writing dictionaries to csv files. extends contextlib.AbstractContextManager

Parameters:
  • name (str) – the name of the file to open
  • fields (list) – a list of field names to use
  • mode (str) – the mode to open the file in
getFile()

returns the file object attached to this instance.

Returns:the file object
Return type:typing.TextIO
write(data: dict)

writes a dict to the file as a row.

Parameters:data (dict) – the row to write
Raises:Exception – if the file is closed or the writer does not exist
writeRows(rows: list)

writes a list of dicts to the file.

Parameters:rows (list) – the list of dicts to write
Raises:Exception – if the file is closed or the writer does not exist
class csv_reader.Writer.CSVWriter(name: str, mode: str = 'a')

Bases: contextlib.AbstractContextManager

the Writer class used to write to csv files. extends contextlib.AbstractContextManager

Parameters:
  • name (str) – the name of the file
  • mode (str) – the mode to open the file in. default is ‘a’
getFile()

returns the file object attached to this instance.

Returns:the file object
Return type:typing.TextIO
write(data: list)

writes a single row to a csv file. the data should be a list of values to write.

Parameters:data (list) – the list containing values to write
Raises:Exception – if the file is closed or the writer does not exist
writeRows(rows: list)

writes multiple rows to a csv file.

Parameters:rows (list) – the rows to write to the file
Raises:Exception – if the file is closed or the writer does not exist