[Tutor] Displaying data in columns

Thomas C. Hicks paradox at pobox.com
Mon May 7 15:43:31 CEST 2012

I have some data that comes out of a database as a list of tuples of
integers and strings, one tuple for each row in the ResultProxy from
the select operation. The data looks something like this:

[(56, 12, 8, u'2012-02', 10, 12, u'Guangxi Province', u'Guangxi',
u'10', 8, u'TOT'), (57, 21, 1, u'2012-03', 36, 21,
u'Sichuan EQ Region', u'Sichuan', u'2', 1, u'Basic Medical -

I would like to display some of the items in the tuples in columnar
format with each column lining up on the left side (below should be
three neat columns with location, training type, number trained and

Guangxi Province	TOT			10	2012-02
Sichuan EQ Region	Basic Medical - Rural	36	2012-03

Surely there is a python module that helps with that, isn't there?  I
know I could write a function that reads the items, figures string
lengths, adds padding white space and prints out the columns but am
hoping there is a more elegant solution.  I am not against reading
documentation, just can't find the right module to read about.


More information about the Tutor mailing list