|
Project Information
Members
Featured
Downloads
|
A Python module to format a simple (i.e. not nested) list into aligned columns. A string with embedded newline characters is returned. For example: import columnize print columnize.columnize(['1', '2', '3', '4'], displaywidth=6) # => '1 3\n2 4\n' gives output: 1 3 2 4 while print columnize.columnize(range(1,5), displaywidth=6, colsep=', ',
arrange_vertical=False)gives output: 1, 2 3, 4 and print columnize.columnize(range(1,6), displaywidth=8) gives output: 1 3 5 2 4 By default entries are left justified: print columnize.columnize(range(1,16), displaywidth=10) gives: 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 while print columnize.columnize(range(1,16), displaywidth=10, ljust=False) produces: 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 Each column is only as wide as necessary. By default, columns are separated by two spaces; one was not legible enough. Set colsep to adjust the string separate columns. Set displaywidth to set the line width. Normally, consecutive items go down from the top to bottom from the left-most column to the right-most. If arrange_vertical is set false, consecutive items will go across, left to right, top to bottom. This module (essentially one function) was lifted from a private method of the same name from Python's cmd Some adjustments and generalizations have been made. |