Table Builder¶
HTMLTable ¶
Helper utility to create HTML (and plain text) tables.
This class is iterable
Iterating over this class will return an iterable, where the first element is the list of headers, and then the rest are the individual rows. Changing values in this iteration will NOT update the original entries.
Example:
table = HTMLTable(caption="My Table")
table.add_columns("number", "value")
table.add_rows("0", "hello world")
table.add_rows("1", "foo bar")
await bot.room_send(
"!example:example.example",
{
"msgtype": "m.notice",
"body": table.render("text"),
"format": "org.matrix.custom.html",
"formatted_body": table.render("html"),
}
)
add_columns ¶
add_columns(*column_names: str) -> Self
Add multiple columns (header names) to the table.
add_row ¶
add_row(*values: str) -> Self
Add a row to the table.
If the number of values is not equal to the number of columns, blank values will be added to pad the row.
render_text ¶
render_text() -> str
Render the table as a simple textual table
Example:
number | value
-------+------
0 | a
1 | b
2 | c
3 | d
4 | e