Skip to main content

planetext-table

Software Version MIT License

Overview

planetext table gengerator.

Example

import datetime as dt
import planetext_table as pt

data = [
    ['file name', 'update date', 'size'],
    ['foo.txt', dt.date(2022, 1, 1), 12000],
    ['bar.txt', dt.date(2022, 2, 3), 500],
    ['ABC.txt', dt.date(2022, 11, 12), 2554500],
]
print(pt.to_ascii(data))

# +------------+-------------+---------+
# | file name  | update date | size    |
# +------------+-------------+---------+
# | foo.txt    | 2022-01-01  | 12000   |
# | bar.txt    | 2022-02-03  | 500     |
# | ABC.txt | 2022-11-12  | 2554500 |
# +------------+-------------+---------+

Reference

to_ascii

Generate ascii table.

+------------+-------------+---------+
| file name  | update date | size    |
+------------+-------------+---------+
| foo.txt    | 2022-01-01  | 12000   |
| bar.txt    | 2022-02-03  | 500     |
| ABC.txt | 2022-11-12  | 2554500 |
+------------+-------------+---------+

arguments

  • data (list[list[Any]])
    • input list data
  • newline (str)
    • newline character at end of line
    • Default: '\n'
  • internal_newline (str)
    • newline character at inside element
    • Default: '\n'
  • aligns (list[Align])
    • text alignment of each column (see below for details)
    • Default: None
  • converters
    • list of type and converter pairs (see below for details)
    • Default: None

to_csv

Generate CSV table.

"file name","update date","size"
"foo.txt","2022-01-01","12000"
"bar.txt","2022-02-03","500"
"ABC.txt","2022-11-12","2554500"

arguments

  • data (list[list[Any]])
    • input list data
  • delimiter (str):
    • delimiter between elements
    • Default: ','
  • quotechar (str):
    • quote character at both ends of element
    • Default: '"'
  • newline (str)
    • newline character at end of line
    • Default: '\n'
  • internal_newline (str)
    • newline character at inside element
    • Default: '\n'
  • converters
    • list of type and converter pairs (see below for details)
    • Default: None

to_markdown

Generate markdown table.

| file name  | update date | size    |
|------------|-------------|---------|
| foo.txt    | 2022-01-01  | 12000   |
| bar.txt    | 2022-02-03  | 500     |
| ABC.txt | 2022-11-12  | 2554500 |

arguments

  • data (list[list[Any]])
    • input list data
  • newline (str)
    • newline character at end of line
    • Default: '\n'
  • internal_newline (str)
    • newline character at inside element
    • Default: '\n'
  • aligns (list[Align])
    • text alignment of each column (see below for details)
    • Default: None
  • converters
    • list of type and converter pairs (see below for details)
    • Default: None

Note

About aligns argument

Liner list for specifying the alignment of each column. Inside values should be the planetext_table.Align enumeration.

If to_ascii, it affects alignment with space padding. If to_markdown, the alignment is specified according to the markdown notation.

The value of the planetext_table.Align is as follows:

  • Align.NONE
  • Align.LEFT
  • Align.CENTER
  • Align.RIGHT

NONE will mean LEFT, but the markdown will no longer use : on the second line.

About converter argument

By default, built-in function str is used to convert the value of each element to a string, but this argument allows any conversion function to be used.

To pass liner list of pairs (tuples) of target element types and conversion functions. It is possible to specify multiple types by making a tuple of element types. (As used in built-in function isinstance)

Example:

import datetime as dt

def int2str(x):
    return f'{x:,}'

def date2str(x):
    return dt.datetime.strftime(x, r'%Y/%m/%d %H:%M:%S.%f')

converter = [
    (int, int2str),
    ((dt.date, dt.datetime), date2str),
]

data = [[10, dt.date(2022, 1, 2)]]
to_ascii(data, converter=converter)

full-width character handling

The character width of full-width characters is determined according to the character type classified by East Asian Width as follows:

character type width
Fullwidth (F) 2
Halfwidth (H) 1
Wide (W) 2
Narrow (Na) 1
Ambiguous (A) 2
Neutral (N) 2

The function unicodedata.east_asian_width from the standard library is used. Some combinations of characters and fonts, such as some symbols and emojis, may not appear to be aligned nicely.

Metadata

Release files for planetext-table 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for planetext-table 0.1.0
File Interpreter ABI Platform
planetext_table-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / planetext_table-0.1.0-py3-none-any.whl

Download URL planetext_table-0.1.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
149e744ac939bbe65786517235d736cd2f19dcea4240e797dce31d5f4969907c
BLAKE2b-256 checksum
How to use checksums
4ce24b05a32c4db62d5bf3af093e11772fb33f4a3048b5c44cc78453e5d2677a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page