API Reference¶
-
csv_reader.Reader.openWithFile(file: TextIO)¶ yields the csv reader object from an already opened file.
Parameters: file (typing.TextIO) – the file obj to use Returns: the reader object Return type: typing.Iterator
-
csv_reader.Reader.openWithName(name: str)¶ opens a csv file as a context manager with the name given.
Parameters: name (str) – the name of the file Returns: the reader object Return type: typing.Iterator
-
csv_reader.Reader.readFromFile(file: TextIO)¶ reads from a file and returns an context manager that yields an iterator.
Parameters: file (typing.TextIO) – the csv file to read from. Returns: the reader object Return type: typing.Iterator
-
csv_reader.Reader.readFromName(name: str)¶ reads from a csv file and returns a context manager that yields an iterator.
Parameters: name (str) – the name of the file Returns: the reader object Return type: typing.Iterator
-
class
csv_reader.Writer.CSVWriter(name: str, mode: str = 'a')¶ Bases:
contextlib.AbstractContextManagerthe 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
-
class
csv_reader.Writer.CSVDictWriter(name: str, fields: list, mode: str = 'a')¶ Bases:
contextlib.AbstractContextManagera 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