MarkdownTable¶
-
class
support.markdown_util.table.
MarkdownTable
(header=None, data=None)¶ Bases:
object
Create a formatted markdown table from some header and data.
header
anddata
should contains strings, asMarkdownTable
makes no attempt to format strings.Examples:
We can set data and header before initializing
>>> header = ["Column 1", "Column 2", "Column 3"] >>> data = [["1","2","3"],["a"*10,"b","c"]] >>> table = MarkdownTable(header=header, data=data) >>> print(table.dump())
… or after
>>> table = MarkdownTable() >>> table.header = ["Column 1", "Column 2", "Column 3"] >>> table.data = [["1","2","3"],["a"*10,"b","c"]] >>> print(table.dump())
Both will produce the following output:
| Column 1 | Column 2 | Column 3 | | ========== | ======== | ======== | | 1 | 2 | 3 | | aaaaaaaaaa | b | c |
We can get individual rows and columns from a MarkdownTable instance:
>>> table.row(0) ["Column 1", "Column 2", "Column 3"] >>> table.column(0) ["Column 1", "1"]
-
header
¶ table header.
- Type
list
-
data
¶ table data.
- Type
list
-
_max_column_size
¶ the maximum size of each column.
- Type
list
Attributes Summary
Methods Summary
column
(i)Get a column, including the header
dump
()Dump header and data into a formatted table string.
row
(i)get a row, where the 0th row is the header.
Attributes Documentation
-
data
¶
-
header
¶
Methods Documentation
-
column
(i)¶ Get a column, including the header
-
dump
()¶ Dump header and data into a formatted table string.
-
row
(i)¶ get a row, where the 0th row is the header.
-