Format a simple (i.e. not nested) list into aligned columns.
Project description
In showing a long lists, sometimes one would prefer to see the value arranged aligned in columns. Some examples include listing methods of an object, listing debugger commands, or showing a numeric array with data aligned.
This is a Python module to format a simple (i.e. not nested) list into aligned columns. A string with embedded newline characters is returned.
Setup
$ python
>>> import columnize
With String data
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.
>>> g = ('bibrons', 'golden', 'madascar', 'leopard', 'mourning', 'suras', 'tokay')
>>> print(columnize.columnize(g, displaywidth=15)
bibrons suras
golden tokay
madascar
leopard
mourning
>>> print(columnize.columnize(g, displaywidth=19, colsep=' | '))
bibrons | suras
golden | tokay
madascar
leopard
mourning
>>> print(columnize.columnize(g, displaywidth=18, colsep=' | ', ljust=False))
bibrons | mourning
golden | suras
madascar | tokay
leopard
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.
With numeric data
>>> print(columnize.columnize(['1', '2', '3', '4'], displaywidth=6)) # => '1 3\n2 4\n')
1 3
2 4
>>> print(columnize.columnize(list(range(1,6)), displaywidth=8))
1 3 5
2 4
By default entries are left justified:
>>> print(columnize.columnize(list(range(1,16)), displaywidth=10))
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15
but you can change that with ljust or if arrange_array is set to True:
>>> print(columnize.columnize(list(range(1,16)), displaywidth=10, ljust=False))
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15
>>> print(columnize.columnize(list(range(1,5)), opts={'arrange_array':True, 'displaywidth':6}))
[1, 2
3, 4]
Credits
This module (essentially one function) was adapted from a private method of the same name from Python’s cmd module. Some adjustments and generalizations have been made.
Other stuff
Authors: Rocky Bernstein rockyb@rubyforge.org
License: MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file columnize-0.3.8.tar.gz.
File metadata
- Download URL: columnize-0.3.8.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c94d9173e0cb34682b1f63d2cea5924a522ef588981a7baa6a4c08a785808555
|
|
| MD5 |
c8ffef9c94c6ccd11e75be15f8c2fc54
|
|
| BLAKE2b-256 |
a90acff7eb29541051ee0cb8f7fdd622ff3d93311103a272e4d37a19a1ba216b
|
File details
Details for the file columnize-0.3.8-py3.3.egg.
File metadata
- Download URL: columnize-0.3.8-py3.3.egg
- Upload date:
- Size: 8.9 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87e7ff2275ff640f2fa98c1dd1b9787da4c73327b3562816660a0cb8a0180249
|
|
| MD5 |
cca31b131edbe6accb11948dc225da5d
|
|
| BLAKE2b-256 |
52fb5bb4d3d9e6929c78a8c89e046cdb9fe0d966e42c6286d5b51a35cc07bbce
|
File details
Details for the file columnize-0.3.8-py3.2.egg.
File metadata
- Download URL: columnize-0.3.8-py3.2.egg
- Upload date:
- Size: 8.9 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77c5d712ca2c86faa8d1550b6c1c22192c8e59ae27fa288d7f92cb56b41d92bc
|
|
| MD5 |
365ac79bc29da9d93989d96adf620426
|
|
| BLAKE2b-256 |
fd49fd3d84ca5849bbadfcb710903be119c1d60e7306baefb1e8302cd648fbe3
|
File details
Details for the file columnize-0.3.8-py2.7.egg.
File metadata
- Download URL: columnize-0.3.8-py2.7.egg
- Upload date:
- Size: 8.9 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb025f81386e482e342281e197262b2b782eaffb10b72da1f61d009cfc1b2ce8
|
|
| MD5 |
5d9565f865e550e9e05f2b15cf2dc8d5
|
|
| BLAKE2b-256 |
bf765d372a23b2dad488984d4867af7a982815dfedc63bca01ee34ef24575378
|
File details
Details for the file columnize-0.3.8-py2.6.egg.
File metadata
- Download URL: columnize-0.3.8-py2.6.egg
- Upload date:
- Size: 9.0 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58693cecc9b82406efdc039b6c525280b6be5adeec2bfafe00d73b4c018530c4
|
|
| MD5 |
18b154acb2e18bc4147ca34b43efcaf2
|
|
| BLAKE2b-256 |
4478cde7853b6369d0144ee153a0a051816125f628cf9f1cd507e5873663527b
|
File details
Details for the file columnize-0.3.8-py2-none-any.whl.
File metadata
- Download URL: columnize-0.3.8-py2-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d5213d604d039662fb2b5639c8df57c9917a78db8fcb152fa4f8eb58c5da9dc
|
|
| MD5 |
b1a61b00b4ff5c430ca18ce02f3e2911
|
|
| BLAKE2b-256 |
dba02dfb72968083b9d09e7eeab0071e6312f95b28cf5c9a0a8ed48e3ac1d0f6
|