Skip to main content

Print a list of strings in columns like in `ls`.

Project description

lscolumn

Print a list of strings in columns like in ls.

Description

Two styles are available -- BSD-style and GNU-style. Let's see through example:

>>> import lscolumn
>>> lscolumn.pprint(['hello', 'hola world', 'greetings', 'hello again and again'],
...                 total_width=60, style='BSD')
hello                 greetings
hola world            hello again and again
>>> lscolumn.pprint(['hello', 'hola world', 'greetings', 'hello again and again'],
...                 total_width=60, style='GNU')
hello  hola world  greetings  hello again and again

In BSD-style, the widths of the columns are the same, whereas in GNU-style, they are different. When formatting long list, BSD-style is faster than GNU-style, but GNU-style is more compact.

CJK (wide) characters are well supported thanks to cjkjust.

Installation

pip install lscolumn

Functions and Classes

For detailed help, try help(...) in Python REPL.

  • pprint(strings, total_width=None, style='BSD', file=None): print in columns the list of strings strings
  • BSDFormatter: the BSD-style formatter (see example below)
  • GNUFormatter: the GNU-style formatter (see example below)

Example using BSDFormatter

import lscolumn
bsd = lscolumn.BSDFormatter(total_width=80)
# print one list
bsd.pprint(['hello', 'hola world', 'greetings'])
# print another list using the same configuration
bsd.pprint(['greetings', 'hello again and again'])
# print yet another list to `outfile`
with open('filename.txt', 'w') as outfile:
    bsd.pprint(['hello', 'hola world'], file=outfile)

The same applies to GNUFormatter.

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

lscolumn-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lscolumn-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file lscolumn-0.1.2.tar.gz.

File metadata

  • Download URL: lscolumn-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for lscolumn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 77b0e967abe57fbb0c9705273cd291b7278cdfd837d7973b8b6642e11a529e19
MD5 a5bbd49ca2bdabd326db425ce257fe3e
BLAKE2b-256 1e746acab3a0d133df35eba200de4b1fea5a22cba18f7a7a89f4bf4ff5584806

See more details on using hashes here.

File details

Details for the file lscolumn-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lscolumn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for lscolumn-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f53453202f614a9efa5351224663db45f28acb68332c04969873d3eaa880ca3
MD5 9668520923e28a4b6c5a42c045097510
BLAKE2b-256 a25108c1d6497fa9d1895385baa12ebc8a9e782aaeafb5e588e4bba2c12613ed

See more details on using hashes here.

Supported by

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