5.1.4.2. Base writer classes of text formats¶
- class pytablewriter.writer.text._text_writer.TextTableWriter(**kwargs: Any)[source]¶
Bases:
AbstractTableWriter
,TextWriterInterface
A base class for table writer with text formats.
- column_delimiter: str¶
A column delimiter of a table.
- char_left_side_row: str¶
A character of a left side of a row.
- char_right_side_row: str¶
A character of a right side of a row.
- char_cross_point: str¶
A character of the crossing point of column delimiter and row delimiter.
- char_opening_row: str¶
A character of the first line of a table.
- char_header_row_separator: str¶
A character of a separator line of the header and the body of the table.
- char_value_row_separator: str¶
A character of a row separator line of the table.
- char_closing_row: str¶
A character of the last line of a table.
- is_write_header_separator_row: bool¶
Write a header separator line of the table if the value is
True
.
- is_write_value_separator_row: bool¶
Write row separator line(s) of the table if the value is
True
.
- is_write_opening_row: bool¶
Write an opening line of the table if the value is
True
.
- is_write_closing_row: bool¶
Write a closing line of the table if the value is
True
.
- is_write_null_line_after_table: bool¶
Write a blank line of after writing a table if the value is
True
.
- margin: int¶
Margin size for each cells
- add_col_separator_style_filter(style_filter: ColSeparatorStyleFilterFunc) None [source]¶
Add a style filter function for columns to the writer.
- Parameters:
style_filter –
A function that called for each cell in the table to apply a style to table cells. The function will be required to implement the following Protocol:
class ColSeparatorStyleFilterFunc(Protocol): def __call__( self, left_cell: Optional[Cell], right_cell: Optional[Cell], **kwargs: Any ) -> Optional[Style]: ...
If more than one style filter function is added to the writer, it will be called from the last one added. These style functions should return
None
when not needed to apply styles. If all of the style functions returnedNone
,default_style
will be applied.You can pass keyword arguments to style filter functions via
style_filter_kwargs
. In default, the attribute includes:writer
: the writer instance that the caller of astyle_filter function
- dump(output: str | IO, close_after_write: bool = True, **kwargs: Any) None [source]¶
Write data to the output with tabular format.
During the executing this method,
enable_ansi_escape
attribute will be temporarily set toFalse
.- Parameters:
output – The value must either an output stream or a path to an output file.
close_after_write – Close the output after write. Defaults to
True
.
- class pytablewriter.writer.text._text_writer.IndentationTextTableWriter(**kwargs: Any)[source]¶
Bases:
TextTableWriter
,IndentationInterface
A base class for table writer with indentation text formats.
- Parameters:
indent_level (int) – Indentation level. Defaults to
0
.
- indent_string¶
Indentation string for each level.