[Tutor] Printing std.out (terminal) with formatted output

Magnus Lyckå magnus@thinkware.se
Thu Jun 19 06:13:01 2003


At 04:38 2003-06-19 -0400, DAVID BABCOCK wrote:
>I am wanting to print some results from a database to the user. Just using 
>the terminal and std.out for right now.

What kind of database are we talking about? An SQL database and
a DB-API 2 complient interface?

>Is there any module that might give some help making the output more 
>readable.
>Saw one called prettyprint that might fit the bill. Just trying to not 
>reinvent the wheel. I did a search on google, not coming up with much do 
>to common words like format and print.

Prettyprint is rather intended to create a half decent result
where you can't predict what the data will look for.

With the kind of tabular data I guess you have, it's not a good choice.

Do you understand how to use format strings and the %-operator?
E.g.

 >>> print '%4i|%10s|%10s' % (5, 'Hello', 'World')
    5|     Hello|     World



--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language