Print python collections as tables
Project description
tprint
Print python collections as tables
Example
from tprint import tprint
data = {
"a": (100, 2, 3, 4),
"b": (1, 200, 3, 4),
"c": (1, 2, 300, 4),
"d": (1, 2, 3, 400),
}
# as rows
tprint(data)
"""
0 | 1 | 2 | 3 | 4
--+-----+-----+-----+----
a | 100 | 2 | 3 | 4
b | 1 | 200 | 3 | 4
c | 1 | 2 | 300 | 4
d | 1 | 2 | 3 | 400
"""
# as columns
tprint(data, as_columns=True)
"""
a | b | c | d
----+-----+-----+----
100 | 1 | 1 | 1
2 | 200 | 2 | 2
3 | 3 | 300 | 3
4 | 4 | 4 | 400
"""
Docs
tprint
This is effectivly just the following snippet:
def tprint(*args, **kwargs):
print(tformat(*args, **kwargs))
tformat
def tformat(
data: Union[Dict[str, Sequence], Sequence],
*,
as_columns: bool = False,
headers: Optional[Sequence[str]] = None,
alignments: Optional[str] = None,
formattings: Optional[str] = None,
) -> str:
"""
Format a dictionary or list as a table.
:param data: table data
:param as_columns: interpret given data as collection of columns
instead of as rows
:param headers: sequence of column headers
(Defaults to enumerating the columns if headers
can't be extracted from data)
:param alignments: string with alignments per column
(Defaults to left alignment for all columns
or those skipped with spaces)
:param formattings: string with formattings per column
(Defaults to string casting for all columns
or those skipped with spaces)
"""
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tprint-1.0.1.tar.gz
(3.1 kB
view details)
File details
Details for the file tprint-1.0.1.tar.gz
.
File metadata
- Download URL: tprint-1.0.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ee94d130a31547b898464f4a045641bb30b0a1769c300c610e5b5ee0ae7a9d |
|
MD5 | 0d5963f8af20901294a176209718a865 |
|
BLAKE2b-256 | 28b8a51e682630e0631b770e93c03b3d6c079b8a6c56316b2bb16b32c200e791 |