Mercurial > mozilla > hg > ProfileManager
view profilemanager/utils.py @ 10:c77e9bef78d6
* update list of public API functions
* further flushing out of profile manager
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 05 May 2010 17:08:47 -0700 |
parents | ca57920aa223 |
children | 145e111903d2 |
line wrap: on
line source
#!/usr/bin/env python def format_tabular(table, spacer=' '): columns = [0 for i in range(max([len(row) for row in table]))] assert (len(columns) == min([len(row) for row in table])) for row in table: for index, column in enumerate(row): if len(column) > columns[index]: columns[index] = len(column) format_string = spacer.join(['%s%s' for i in range(len(columns))]) retval = [] for row in table: values = [] for index, column in enumerate(row): values.append(column) values.append(' ' * (columns[index] - len(column))) retval.append(format_string % tuple(values)) return '\n'.join(retval) if __name__ == '__main__': test_data = [ ['fox', 'i am a fox!', 'Foxkeh'], ['cat', 'meow', 'Lilly'], ['elephant', 'elephants shower with their trunks', 'Elephino'] ] print format_tabular(test_data)