Structured writing to console, such as a table

Dave Kuhlman dkuhlman at rexx.com
Mon Sep 1 17:09:12 EDT 2003


Raaijmakers, Vincent (IndSys, GE Interlogix) wrote:

> Ok, perhaps a question on a newbie level.
> 
> I try to create a simple 'write to a console application' where
> all the items in a string do have a variable size:
> items = ["a", "bbbbbbbbb", "cc"]
> Well, actually, I need to print a table as simple text, nice lined
> up in a console. So:
> 
> 
> Item:       Value:     Another Value:
> ----------+----------+------------------
> a         | 1        | 2
> bbbbbbbbb | 2        | 17
> cc        | 3        | 5
> 
> My hope was that somewhere in python land an existing module was
> waiting for me. A module that also prints lines, headers....
> 
> Unfortunately, I can't find it. Books, Google...
> Before I reinvent this wheel... please give me some tips,
> references, examples...

This is not a solution to your problem, but is something that you
may want to know.  Docutils and the reStructuredText that it
processes support the kind of ASCII tables that you describe.  You
may want to check the Docutils/reStructuredText specification.  If
you follow that specification you will be able to send your
tables through a Docutil tool to produces HTML, LaTeX, etc.

Docutils, by the way, is implemented in Python.

See:

    http://docutils.sourceforge.net/docs/rst/quickref.html#tables
    http://docutils.sourceforge.net/
    https://sourceforge.net/projects/docutils/

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com




More information about the Python-list mailing list