Python 3 library to create properly aligned Markdown tables
Project description
Python Markdown tables
With this simple library you can easily generate the Markdown source code for a table.
The library is written for Python 3. As of now it's only been tested with version 3.7 of the language, but I think it should also work with 3.6. Open an issue to let me know how it goes!
Example
from mdtables import Table, Column
t = Table(
Column('n'),
Column('2·n', alignment='center'),
Column('n²', alignment='right' )
)
numbers = (1, 6, 19, 59)
for n in numbers:
t.row(n, 2*n, n*n)
print(t)
prints
|n |2·n| n²|
|--|:-:|---:|
|1 | 2 | 1|
|6 |12 | 36|
|19|38 | 361|
|59|118|3481|
Column options
header
: the only required argument: the name of the column.alignment
: how text should be aligned in the column. Possible values areleft
(default),center
andright
.width
: the width of the column. The default isNone
, which uses the smallest possible width that fits all content.format
: the format option used on all data inside cells (not in the header). This is part of a Python format string, it will be used like this:'{:
<width><alignment><format option comes here>}'.format(…)
. The default isstr.format
's default (like when you use just{}
without any formatting options).headerformat
: the format option used on the header. Analog toformat
above.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mdtables-1.1.0.tar.gz
(16.5 kB
view hashes)
Built Distribution
mdtables-1.1.0-py3-none-any.whl
(17.2 kB
view hashes)