ascii tables

Bengt Richter bokr at oz.net
Mon Jun 2 14:56:11 EDT 2003


On Fri, 30 May 2003 00:37:46 +0200, Carel Fellinger <carel.fellinger at chello.nl> wrote:

>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
>
Agreed, but IMO this boxed format is not too bad
an alternative (and if you have a font with box
characters it can look pretty nice).

   +--------+-----+-----+--------+--------+
   | 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.
>
>

Regards,
Bengt Richter




More information about the Python-list mailing list