Structured writing to console, such as a table

Paul Moore paul.moore at atosorigin.com
Tue Sep 2 11:49:12 CEST 2003


Bob Gailer <bgailer at alum.rpi.edu> wrote in message news:<mailman.1062465724.6721.python-list at python.org>...
 
> In addition to other responses, consider this which uses nested % 
> formatting to make format strings for reuse:

I like this one! Very simple, and the resulting code is easy to
understand.

Most of my code's complexity revolved around getting the column
widths, which you don't address - this is good, as it makes the
separation of issues clearer. One other issue which sometimes bites
me, when I need to print database tables, is whether to truncate
values which are too long for their field widths. It's another issue
the OP didn't specify a preference over. No criticism there, it's just
an illustration that for problems like this, knowing what you want is
often the bigger issue than writing code to do it... (A friend of mine
used to love quoting the example of functions to "ask for a yes/no
response", where it's nearly always easier to write your own version
than to work around the ways in which a canned version doesn't *quite*
meet your needs...)

In Python, reinventing wheels is often easy enough that it's not worth
the design effort of making things like this into truly reusable
library code. I can't work out if that's an advantage of Python :-)

Paul.




More information about the Python-list mailing list