Skip to main content

A simple library to build plain text tables

Project description

Plaintable is a very simple library to build plain text tables. It has been created to provide a very lightweight and clear interface for generating plain text tables. Some data can be customized e.g. alignment, padding and floatprecision. Every data item is to be converted to string automatically.

Usage

>>> from plaintable import Table
>>> data = [
...     [1, 2, 3, 4, 5],
...     [10, 11, 12, 13, 14],
...     ['a', 'b', 'c', 'd', 'e'],
...     [1.0, 2.0, 1.5, 4.25, 10.50],
... ]
>>> headline = ['one', 'two', 'three', 'four', 'five']
>>> table = Table(data, headline)
>>> print(table)
one   two   three  four  five
----  ----  -----  ----  -----
1     2     3      4     5
10    11    12     13    14
a     b     c      d     e
1.00  2.00  1.50   4.25  10.50

Customise

The table layout can be customised by passing several keyword arguments to Table.__init__().

headline

A list of strings which will appear as column headers. This argument is optional.

Default: None

align

You can specifiy the alignment of the table (‘l’, ‘r’, ‘c’).

Default: ‘l’

padding

If you need a wider table you can increase the padding.

Default: 2

floatprec

Every float value is converted to str with this precision.

Default: 2

header_padding

Adds extra spaces around header fields.

Default: 0

datetimefs

Specifies the datetime formatstring. Any datetime object is converted to a string refering to this formatstring; see also here.

Default: %Y-%m-%d %H:%M

Further Examples

>>> from plaintable import Table
>>> data = [
...    [1, 2, 3, 4, 5],
...    [10, 11, 12, 13, 14],
...    ['a', 'b', 'c', 'd', 'e'],
...    [1.0, 2.0, 1.5, 4.25, 10.50],
... ]
>>> headline = ['one', 'two', 'three', 'four', 'five']
>>> table = Table(data, headline, align='r', padding=4, floatprec=4)
>>> print(table)
       one       two     three      four       five
    ------    ------    ------    ------    -------
         1         2         3         4          5
        10        11        12        13         14
         a         b         c         d          e
    1.0000    2.0000    1.5000    4.2500    10.5000
>>> from plaintable import Table
>>> data = [
...    [1, 2, 3, 4, 5],
...    [10, 11, 12, 13, 14],
...    ['a', 'b', 'c', 'd', 'e'],
...    [1.0, 2.0, 1.5, 4.25, 10.50],
... ]
>>> table = Table(data)
>>> print(table)
1     2     3     4     5
10    11    12    13    14
a     b     c     d     e
1.00  2.00  1.50  4.25  10.50
>>> from plaintable import Table
>>> data = [
...    [1, 2, 3, 4, 5],
...    [10, 11, 12, 13, 14],
...    ['a', 'b', 'c', 'd', 'e'],
...    [1.0, 2.0, 1.5, 4.25, 10.50],
... ]
>>> table = Table(data, padding=4)
>>> print(table)
1       2       3       4
10      11      12      13
a       b       c       d
1.00    2.00    1.50    4.25
>>> from plaintable import Table
>>> data = [
...    [1, 2, 3, 4, 5],
...    [10, 11, 12, 13, 14],
...    ['a', 'b', 'c', 'd', 'e'],
...    [1.0, 2.0, 1.5, 4.25, 10.50],
... ]
>>> table = Table(data, header_padding=4)
>>> print(table)
one          two          three          four
-----------  -----------  -------------  ------------
1            2            3              4
10           11           12             13
a            b            c              d
1.00         2.00         1.50           4.25

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for plaintable, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size plaintable-0.1.1.tar.gz (4.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page