Skip to main content

No project description provided

Project description

collist is a simple module which provides the function collist(), the single purpose of which is to columnate lists of output for printing to the terminal. It is very much like the unix command column, but it works on python iterables. This package also exports the command cols which is similar to column but works better (on my system), though it has fewer options; see cols --help.

The program uses the tput command internally, and therefore will not work with Windows and other strange, non-POSIX operation systems.

Monkey Patch collist into the Python Interactive Prompt

The Python interactive prompt print the representation of the return value of any expression you give it. If that return value is a list, dictionary, or tuple, It returns the literal that will produce the object.

When these collection objects get rather longer, printing them sucks. collist is designed to make lists of things look better. collist has a representation function which will output a nicely columnated repr of a python dictionary, list or tuple. This repr is a valid python literal.

In order to get this behavior in the standard interactive prompt or bpython, add this to your ~/.pystart:

import sys # if you haven't already.
from collist import displayhook

sys.displayhook = displayhook

Then, you’ll get nicely columnated list, tuples and dictionaries back in the interactive prompt.

>>> [i for i in ('foo bar bing ' * 15).split()]
['foo',  'bar',  'bing', 'foo',  'bar',  'bing', 'foo',  'bar',
 'bing', 'foo',  'bar',  'bing', 'foo',  'bar',  'bing', 'foo',
 'bar',  'bing', 'foo',  'bar',  'bing', 'foo',  'bar',  'bing',
 'foo',  'bar',  'bing', 'foo',  'bar',  'bing', 'foo',  'bar',
 'bing', 'foo',  'bar',  'bing', 'foo',  'bar',  'bing', 'foo',
 'bar',  'bing', 'foo',  'bar',  'bing']

Nice! This is what the people want. There is a bug at the moment where the terminal size is stuck at whatever it was when the interactive prompt was started. I assume this has something to do with tput getting the terminal size from sterr, but I’m not really sure. If anyone has a fix, I will be glad to accept a patch.

Also this patch won’t work in ipython, since it has it’s own replacement for displayhook, of which I know nothing. It prints nicely already. kind of.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collist-0.5.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

collist-0.5-py2.py3-none-any.whl (5.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file collist-0.5.tar.gz.

File metadata

  • Download URL: collist-0.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for collist-0.5.tar.gz
Algorithm Hash digest
SHA256 e4d443ea9ae63d45733ca5a84ff9baad2133bd933a5021c0731ba1d2108a838e
MD5 0565e29036d7e4471a80b05563c3cb18
BLAKE2b-256 70533b1f0829d7559ec1dc2e7088746b417ca8baeaed5cc8620545c25587043a

See more details on using hashes here.

File details

Details for the file collist-0.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for collist-0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c0ad9936f63a1ca7678cb3afadd7ea3da2a9dccbbea7cd0d2452f12e04e132b8
MD5 d77c09c2df1c95899d64aa7fc007dac5
BLAKE2b-256 7fad5aa5ea7d27133cb40eb5a89ed01caba4db3b8e4a1e72415647d709be3e90

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page