ascii tables

Carel Fellinger carel.fellinger at chello.nl
Thu May 29 18:37:46 EDT 2003


On Thu, May 29, 2003 at 02:01:47PM -0500, John Hunter wrote:
...
> Here is my first pass at a solution, which prints
> 
>     Name   | Age | Sex | Weight | Height
>     ------------------------------------
>     John   |  35 |  M  |  170.0 |   60.1
>     ------------------------------------
>     Miriam |  31 |  F  |  135.0 |   58.2
>     ------------------------------------
>     Rahel  |   5 |  F  |   40.0 |   48.2
>     ------------------------------------
>     Ava    |   2 |  F  |   25.0 |   30.0

it's old printer wisdom that one should be very reluctant to use lines
in tables, and indeed I find the following much easier on the eyes:

    Name   : Age : Sex : Weight : Height
    ------------------------------------
    John      35    M     170.0     60.1
    Miriam    31    F     135.0     58.2
    Rahel      5    F      40.0     48.2
    Ava        2    F      25.0     30.0

use atleast 3 spaces to seperate columns and you won't need that ugly bar.


...
>     def pad_entry(entry, align, width):

you could also use str's center, ljust and rjust methods.


-- 
groetjes, carel





More information about the Python-list mailing list