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 stringsstrings
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.1.1.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for lscolumn-0.1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e37e28108b91fa43caa21cfcde3d92edac7c03534b8b01a93a89e86f9d22c7 |
|
MD5 | a81a674b8a12e64272154b2b37d5c9f7 |
|
BLAKE2b-256 | c443563fa11d47a8386594c0ecce9aea78d634f56847c1b85cda9709a84b5699 |