Ascii Table Packages

Ascii Table Packages

  • text_table
  • texttable

 

text_table

>>> t = TextTable((5, 'abc'), (10, 'def'))
>>> t.row('foobarbaz', 'yadayadayada')
>>> print t.draw()

.-------+------------.
| abc   | def        |
+-------+------------+
| foob- | yadayaday- |
| arbaz | ada        |
'-------+------------'

 


texttable

available on PyPI.

Example:

    table = Texttable()
    table.set_cols_align(["l", "r", "c"])
    table.set_cols_valign(["t", "m", "b"])
    table.add_rows([ ["Name", "Age", "Nickname"],
                     ["Mr\nXavier\nHuon", 32, "Xav'"],
                     ["Mr\nBaptiste\nClement", 1, "Baby"] ])
    print table.draw() + "\n"

Result:

    +----------+-----+----------+
    |   Name   | Age | Nickname |
    +==========+=====+==========+
    | Mr       |     |          |
    | Xavier   |  32 |          |
    | Huon     |     |   Xav'   |
    +----------+-----+----------+
    | Mr       |     |          |
    | Baptiste |   1 |          |
    | Clement  |     |   Baby   |
    +----------+-----+----------+

table = Texttable()

table.set_deco(Texttable.HEADER)

table.set_cols_dtype(['t',  # text
                      'f',  # float (decimal)
                      'e',  # float (exponent)
                      'i',  # integer
                      'a']) # automatic
                      
table.set_cols_align(["l", "r", "r", "r", "l"])

table.add_rows([["text",    "float", "exp", "int", "auto"],
                ["abcd",    "67",    654,   89,    128.001],
                ["efghijk", 67.5434, .654,  89.6,  12800000000000000000000.00023],
                ["lmn",     5e-78,   5e-78, 89.4,  .000000000000128],
                ["opqrstu", .023,    5e+78, 92.,   12800000000000000000000]])
print table.draw()
    
Result:

text   float       exp      int     auto
===========================================
abcd   67.000   6.540e+02   89    128.001
efgh   67.543   6.540e-01   90    1.280e+22
ijkl   0.000    5.000e-78   89    0.000
mnop   0.023    5.000e+78   92    1.280e+22
  

 

 

 

 

 

 

Creative Commons license icon Creative Commons license icon