Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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
Release History

Release History

This version
History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
plaintable-0.1.1.tar.gz (4.8 kB) Copy SHA256 Checksum SHA256 Source Oct 11, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting