tableread package¶
Tableread package to read a text file table into a Python object.
-
class
tableread.BaseRSTDataObject[source]¶ Bases:
objectBase Class for RST Table Data handling.
-
column_default_separator= '='¶
-
column_divider_char= ' '¶
-
comment_char= '#'¶
-
data_format: Any = None¶
-
header_divider= '='¶
-
header_markers= {'!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'}¶
-
-
exception
tableread.InvalidFileException[source]¶ Bases:
ExceptionException for improperly formatted files.
-
class
tableread.SimpleRSTReader(rst_source)[source]¶ Bases:
tableread.BaseRSTDataObjectRepresent all tables found in a RST file.
Determine from where to parse RST content and then parse it.
- Parameters
rst_source (
str) – The source of the RST content to parse. This can either be a file path with a.rstextension, or a string containing the RST content.
-
data_format¶ alias of
collections.OrderedDict
-
property
first¶ Return the first table found in the document.
-
property
tables¶ Get the list of table names found in the document.
-
class
tableread.SimpleRSTTable(divider_row, header, rows)[source]¶ Bases:
tableread.BaseRSTDataObjectRepresent a single table from a RST file.
Build a table from the text string parts.
- Parameters
divider_row (
str) – the row above or below the table headers, consisting solely of “=” and spaces, that delineates the column boundaries.header (
str) – the column header rowrows (
List[str]) – the rows within the table containing data
-
data_format¶ alias of
builtins.list
-
exclude_by(**kwargs)[source]¶ Filter data to exclude items matching conditions.
Given a set of key/value filters, returns a new TableRead object without the matching data, that can be iterated over. Kwarg values may be a simple value (str, int) or a function that returns a boolean.
Note: When filtering both keys and values are not case sensitive.
-
get_fields(*fields)[source]¶ Get only specified fields from data.
Given a set of fields, returns a list of those field values from each entry. A single field will return a list of values, Multiple fields will return a list of tuples of values.
-
matches_all(**kwargs)[source]¶ Filter data for a positive match to conditions.
Given a set of key/value filters, returns a new TableRead object with the filtered data, that can be iterated over. Kwarg values may be a simple value (str, int) or a function that returns a boolean.
Note: When filtering both keys and values are not case sensitive.
-
tableread.get_specific_attr_matcher(key, value)[source]¶ Check if a given attribute value matches the expected value.
- Parameters
key (
str) – the name of the attribute to checkvalue (
str) – the expected string value
- Returns
a checker that will accept an object and return True if the attribute value matches, or False if not.
- Return type
function
-
tableread.safe_list_index(a_list, index_value, default=None)[source]¶ Return the value at the given index, or a default if index does not exist.
- Parameters
a_list (
list) – the list to be indexedindex_value (
int) – the desired index position from the listdefault (
Optional[Any]) – the default value to return if the given index does not exist
- Returns
the value at the list index position or the default
- Return type
any
Submodules¶
tableread.writer module¶
Tableread module to write a text file from a Python object.
-
class
tableread.writer.SimpleRSTTableWriteable(title, row_data)[source]¶ Bases:
objectSingle rST table object to be written.
-
property
divider¶ Format divider row as a spaced string.
-
divider_char= '='¶
-
property
headers¶ Headers for the table, formatted as a spaced string.
-
title_marker= '~'¶
-
property
-
class
tableread.writer.SimpleRSTWriter(file_path, *tables)[source]¶ Bases:
objectWrite a .rst file from a list of tables.
Accept a list of table information and write to file.
- Parameters
file_path (
str) – the path to write the output filetables (
Tuple[str,List[dict]]) – Each a tuple of table title (str) and list of row dicts