Skip to main content

To create text-based columnified (ls-like) content suitable for console output from a list of strings

Project description

columnify

PyPI - Version PyPI - Python Version


columnify creates text-based columnified (ls-like) content suitable for console output from list of strings.

Columns are automatically resized to fit the content of the largest cell. Each cell will be padded with spaces to fill the available space and ensure column contents are left-aligned.

Table of Contents

Usage

Default

import shutil

import columnify


given: list[str] = [
  "Canidae",
  "Felidae",
  "Cat",
  "Cattle",
  "Dog",
  "Donkey",
  "Goat",
  "Guinea pig",
  "Horse",
  "Pig",
  "Rabbit",
  "Fancy rat varieties",
  "laboratory rat strains",
]

output: str = columnify.columnify(given, shutil.get_terminal_size().columns)

print(output)

Output

Canidae  Cat     Dog     Goat        Horse  Rabbit               laboratory rat strains
Felidae  Cattle  Donkey  Guinea pig  Pig    Fancy rat varieties

Horizon first

print(columnify.columnify(given, shutil.get_terminal_size().columns), horizon_first=True)

Output

Canidae     Felidae  Cat  Cattle  Dog                  Donkey                  Goat
Guinea pig  Horse    Pig  Rabbit  Fancy rat varieties  laboratory rat strains

Installation

pip install columnify

API

Methods

columnify(
    items: list[str],
    line_width: int,
    indent: int = 0,
    delimiter: str = '  ',
    horizon_first: bool = False) -> str

License

columnify is distributed under the terms of the MPL-2.0 license.

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

columnify-0.0.2.tar.gz (10.5 kB view hashes)

Uploaded Source

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