Reading
This module provides a set of utilities for reading TSV files.
-
class mysqltsv.reader.Reader(f, headers=True, types=None, none_string='NULL', error_handler=<function raise_exception at 0x2adc172a9d08>)[source]
Constructs a new TSV row reader – which acts as an iterable of
AbstractRow.
Parameters: |
- f : file
A file pointer
- headers : bool | list`(`str)
If True, read the first row of the file as a set of headers. If a
list of str is provided, use those strings as headers. Otherwise,
assume no headers.
- types : list`( `callable )
A list of callable to apply to the row values. If none is
provided, all values will be read as str
- none_string : str
A string that will be interpreted as None when read. (Defaults to
“NULL”)
- error_handler : callable
A function that takes three arguements (lineno, line, exception)
that handles an error during row reading. The default behavior is
to throw a mysqltsv.errors.RowReadingError
|
list`(`str) : A list of headers if provided
-
mysqltsv.functions.read(f, *args, **kwargs)[source]
Reads a file and returns an iterator of
AbstractRow.
Parameters: |
- f : file
A file pointer
- headers : bool | list`(`str)
If True, read the first row of the file as a set of headers. If a
list of str is provided, use those strings as headers. Otherwise,
assume no headers.
- types : list`( `callable )
A list of callable to apply to the row values. If none is
provided, all values will be read as str
- none_string : str
A string that will be interpreted as None when read. (Defaults to
“NULL”)
- error_handler : callable
A function that takes three arguements (lineno, line, exception)
that handles an error during row reading. The default behavior is
to throw a mysqltsv.errors.RowReadingError
|