Skip to content

mrjohannchang/columnify.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

columnify

Inspired by columnify.

columnify creates text-based columnized (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 aligned.

Table of Contents

Examples

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

Default

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

Horizon first

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

center()

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

rjust()

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

Custom delimiter ( | )

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

Indent (4 spaces):

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

See examples/example.py for more information.

Installation

pip install columnify

API

Methods

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

License

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

About

Creating text-based columnized (ls-like) content suitable for console output from list of strings.

Topics

Resources

License

Stars

Watchers

Forks

Languages