prettytable 3.17.0__tar.gz → 3.18.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/dependabot.yml +13 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/labels.yml +2 -2
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/lint.yml +6 -6
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/release-drafter.yml +15 -7
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/release.yml +6 -6
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/require-pr-label.yml +1 -1
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/workflows/test.yml +17 -5
- {prettytable-3.17.0 → prettytable-3.18.0}/.pre-commit-config.yaml +11 -10
- {prettytable-3.17.0 → prettytable-3.18.0}/PKG-INFO +109 -14
- {prettytable-3.17.0 → prettytable-3.18.0}/README.md +105 -11
- {prettytable-3.17.0 → prettytable-3.18.0}/pyproject.toml +20 -29
- prettytable-3.18.0/requirements-mypy.txt +2 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/src/prettytable/__init__.py +6 -1
- prettytable-3.18.0/src/prettytable/_version.py +24 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/src/prettytable/colortable.py +24 -11
- {prettytable-3.17.0 → prettytable-3.18.0}/src/prettytable/prettytable.py +510 -292
- prettytable-3.18.0/tests/data/table_align_center.txt +6 -0
- prettytable-3.18.0/tests/data/table_align_left.txt +6 -0
- prettytable-3.18.0/tests/data/table_align_right.txt +6 -0
- prettytable-3.18.0/tests/data/table_ansi_colors.txt +7 -0
- prettytable-3.18.0/tests/data/table_cjk.txt +6 -0
- prettytable-3.18.0/tests/data/table_combining_chars.txt +6 -0
- prettytable-3.18.0/tests/data/table_complex_emoji.txt +7 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_colortable.py +2 -2
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_html.py +65 -73
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_json.py +2 -8
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_mediawiki.py +2 -8
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_prettytable.py +441 -137
- prettytable-3.18.0/tests/test_rst.py +97 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_sorting.py +44 -15
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_style.py +186 -36
- {prettytable-3.17.0 → prettytable-3.18.0}/tox.ini +4 -2
- prettytable-3.17.0/.github/zizmor.yml +0 -7
- prettytable-3.17.0/requirements-mypy.txt +0 -3
- prettytable-3.17.0/src/prettytable/_version.py +0 -34
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/FUNDING.yml +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/SECURITY.md +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/labels.yml +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.github/release-drafter.yml +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/.gitignore +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/CHANGELOG.md +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/LICENSE +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/RELEASING.md +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/src/prettytable/__main__.py +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/src/prettytable/py.typed +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/conftest.py +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_latex.py +0 -0
- {prettytable-3.17.0 → prettytable-3.18.0}/tests/test_sections.py +0 -0
|
@@ -5,6 +5,10 @@ updates:
|
|
|
5
5
|
schedule:
|
|
6
6
|
interval: monthly
|
|
7
7
|
time: "03:00"
|
|
8
|
+
groups:
|
|
9
|
+
actions:
|
|
10
|
+
patterns:
|
|
11
|
+
- "*"
|
|
8
12
|
open-pull-requests-limit: 10
|
|
9
13
|
labels:
|
|
10
14
|
- "changelog: skip"
|
|
@@ -14,12 +18,21 @@ updates:
|
|
|
14
18
|
update-types:
|
|
15
19
|
- "version-update:semver-minor"
|
|
16
20
|
- "version-update:semver-patch"
|
|
21
|
+
cooldown:
|
|
22
|
+
default-days: 7
|
|
23
|
+
|
|
17
24
|
- package-ecosystem: pip
|
|
18
25
|
directory: "/"
|
|
19
26
|
schedule:
|
|
20
27
|
interval: monthly
|
|
21
28
|
time: "03:00"
|
|
29
|
+
groups:
|
|
30
|
+
pip:
|
|
31
|
+
patterns:
|
|
32
|
+
- "*"
|
|
22
33
|
open-pull-requests-limit: 10
|
|
23
34
|
labels:
|
|
24
35
|
- "changelog: skip"
|
|
25
36
|
- "dependencies"
|
|
37
|
+
cooldown:
|
|
38
|
+
default-days: 7
|
|
@@ -14,10 +14,10 @@ jobs:
|
|
|
14
14
|
pull-requests: write
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
16
|
steps:
|
|
17
|
-
- uses: actions/checkout@
|
|
17
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
18
18
|
with:
|
|
19
19
|
persist-credentials: false
|
|
20
|
-
- uses: micnncim/action-label-syncer@v1
|
|
20
|
+
- uses: micnncim/action-label-syncer@3abd5ab72fda571e69fffd97bd4e0033dd5f495c # v1.3.0
|
|
21
21
|
with:
|
|
22
22
|
prune: false
|
|
23
23
|
env:
|
|
@@ -13,25 +13,25 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
|
|
15
15
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
16
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
17
17
|
with:
|
|
18
18
|
persist-credentials: false
|
|
19
|
-
- uses: actions/setup-python@v6
|
|
19
|
+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
20
20
|
with:
|
|
21
21
|
python-version: "3.x"
|
|
22
|
-
- uses: j178/prek-action@
|
|
22
|
+
- uses: j178/prek-action@cbc2f23eb5539cf20d82d1aabd0d0ecbcc56f4e3 # v2.0.2
|
|
23
23
|
|
|
24
24
|
mypy:
|
|
25
25
|
runs-on: ubuntu-latest
|
|
26
26
|
|
|
27
27
|
steps:
|
|
28
|
-
- uses: actions/checkout@
|
|
28
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
29
29
|
with:
|
|
30
30
|
persist-credentials: false
|
|
31
|
-
- uses: actions/setup-python@v6
|
|
31
|
+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
32
32
|
with:
|
|
33
33
|
python-version: "3.x"
|
|
34
34
|
- name: Install uv
|
|
35
|
-
uses: astral-sh/setup-uv@
|
|
35
|
+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
|
|
36
36
|
- name: Mypy
|
|
37
37
|
run: uvx --with tox-uv tox -e mypy
|
|
@@ -16,16 +16,24 @@ on:
|
|
|
16
16
|
|
|
17
17
|
jobs:
|
|
18
18
|
update_release_draft:
|
|
19
|
-
if:
|
|
19
|
+
if: |
|
|
20
|
+
github.event.repository.fork == false
|
|
21
|
+
&& github.event_name != 'pull_request'
|
|
20
22
|
permissions:
|
|
21
23
|
# write permission is required to create a GitHub Release
|
|
22
24
|
contents: write
|
|
25
|
+
runs-on: ubuntu-slim
|
|
26
|
+
steps:
|
|
27
|
+
# Drafts your next release notes as pull requests are merged into "main"
|
|
28
|
+
- uses: release-drafter/release-drafter@5de93583980a40bd78603b6dfdcda5b4df377b32 # v7.2.0
|
|
29
|
+
|
|
30
|
+
autolabeler:
|
|
31
|
+
if: |
|
|
32
|
+
github.event.repository.fork == false
|
|
33
|
+
&& github.event_name == 'pull_request'
|
|
34
|
+
permissions:
|
|
23
35
|
# write permission is required for autolabeler
|
|
24
|
-
# otherwise, read permission is required at least
|
|
25
36
|
pull-requests: write
|
|
26
|
-
runs-on: ubuntu-
|
|
37
|
+
runs-on: ubuntu-slim
|
|
27
38
|
steps:
|
|
28
|
-
|
|
29
|
-
- uses: release-drafter/release-drafter@v6
|
|
30
|
-
env:
|
|
31
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
39
|
+
- uses: release-drafter/release-drafter/autolabeler@5de93583980a40bd78603b6dfdcda5b4df377b32 # v7.2.0
|
|
@@ -20,12 +20,12 @@ jobs:
|
|
|
20
20
|
runs-on: ubuntu-latest
|
|
21
21
|
|
|
22
22
|
steps:
|
|
23
|
-
- uses: actions/checkout@
|
|
23
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
24
24
|
with:
|
|
25
25
|
fetch-depth: 0
|
|
26
26
|
persist-credentials: false
|
|
27
27
|
|
|
28
|
-
- uses: hynek/build-and-inspect-python-package@v2
|
|
28
|
+
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
|
|
29
29
|
|
|
30
30
|
# Publish to Test PyPI on every commit on main.
|
|
31
31
|
release-test-pypi:
|
|
@@ -42,13 +42,13 @@ jobs:
|
|
|
42
42
|
|
|
43
43
|
steps:
|
|
44
44
|
- name: Download packages built by build-and-inspect-python-package
|
|
45
|
-
uses: actions/download-artifact@
|
|
45
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
46
46
|
with:
|
|
47
47
|
name: Packages
|
|
48
48
|
path: dist
|
|
49
49
|
|
|
50
50
|
- name: Publish to Test PyPI
|
|
51
|
-
uses: pypa/gh-action-pypi-publish@
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
|
52
52
|
with:
|
|
53
53
|
repository-url: https://test.pypi.org/legacy/
|
|
54
54
|
|
|
@@ -67,10 +67,10 @@ jobs:
|
|
|
67
67
|
|
|
68
68
|
steps:
|
|
69
69
|
- name: Download packages built by build-and-inspect-python-package
|
|
70
|
-
uses: actions/download-artifact@
|
|
70
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
71
71
|
with:
|
|
72
72
|
name: Packages
|
|
73
73
|
path: dist
|
|
74
74
|
|
|
75
75
|
- name: Publish to PyPI
|
|
76
|
-
uses: pypa/gh-action-pypi-publish@
|
|
76
|
+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
|
@@ -20,38 +20,50 @@ jobs:
|
|
|
20
20
|
- "3.15"
|
|
21
21
|
- "3.14t"
|
|
22
22
|
- "3.14"
|
|
23
|
-
- "3.13t"
|
|
24
23
|
- "3.13"
|
|
25
24
|
- "3.12"
|
|
26
25
|
- "3.11"
|
|
27
26
|
- "3.10"
|
|
28
27
|
os: [windows-latest, macos-latest, ubuntu-latest]
|
|
28
|
+
include:
|
|
29
|
+
- python-version: "3.16"
|
|
30
|
+
os: ubuntu-latest
|
|
31
|
+
- python-version: "3.16t"
|
|
32
|
+
os: ubuntu-latest
|
|
29
33
|
|
|
30
34
|
steps:
|
|
31
|
-
- uses: actions/checkout@
|
|
35
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
32
36
|
with:
|
|
33
37
|
persist-credentials: false
|
|
34
38
|
|
|
35
39
|
- name: Set up Python ${{ matrix.python-version }}
|
|
36
|
-
uses: actions/setup-python@v6
|
|
40
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
41
|
+
if: "!startsWith(matrix.python-version, '3.16')"
|
|
37
42
|
with:
|
|
38
43
|
python-version: ${{ matrix.python-version }}
|
|
39
44
|
allow-prereleases: true
|
|
40
45
|
|
|
46
|
+
- name: Set up Python ${{ matrix.python-version }} (deadsnakes)
|
|
47
|
+
uses: deadsnakes/action@e640ac8743173a67cca4d7d77cd837e514bf98e8 # v3.2.0
|
|
48
|
+
if: startsWith(matrix.python-version, '3.16')
|
|
49
|
+
with:
|
|
50
|
+
python-version: "3.16-dev"
|
|
51
|
+
nogil: ${{ endsWith(matrix.python-version, 't') }}
|
|
52
|
+
|
|
41
53
|
- name: Set PYTHON_GIL
|
|
42
54
|
if: endsWith(matrix.python-version, 't')
|
|
43
55
|
run: |
|
|
44
56
|
echo "PYTHON_GIL=0" >> "$GITHUB_ENV"
|
|
45
57
|
|
|
46
58
|
- name: Install uv
|
|
47
|
-
uses: astral-sh/setup-uv@
|
|
59
|
+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
|
|
48
60
|
|
|
49
61
|
- name: Tox tests
|
|
50
62
|
run: |
|
|
51
63
|
uvx --python ${{ matrix.python-version }} --with tox-uv tox -e py
|
|
52
64
|
|
|
53
65
|
- name: Upload coverage
|
|
54
|
-
uses: codecov/codecov-action@
|
|
66
|
+
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
|
|
55
67
|
with:
|
|
56
68
|
flags: ${{ matrix.os }}
|
|
57
69
|
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
repos:
|
|
2
2
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
-
rev: v0.
|
|
3
|
+
rev: v0.15.9
|
|
4
4
|
hooks:
|
|
5
5
|
- id: ruff-check
|
|
6
6
|
args: [--exit-non-zero-on-fix]
|
|
7
7
|
|
|
8
8
|
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
9
|
-
rev:
|
|
9
|
+
rev: 26.3.1
|
|
10
10
|
hooks:
|
|
11
11
|
- id: black
|
|
12
12
|
|
|
@@ -26,38 +26,39 @@ repos:
|
|
|
26
26
|
exclude: .github/ISSUE_TEMPLATE/bug_report.md|tests/test_style.py|tests/test_prettytable.py
|
|
27
27
|
|
|
28
28
|
- repo: https://github.com/python-jsonschema/check-jsonschema
|
|
29
|
-
rev: 0.
|
|
29
|
+
rev: 0.37.1
|
|
30
30
|
hooks:
|
|
31
31
|
- id: check-dependabot
|
|
32
32
|
- id: check-github-workflows
|
|
33
33
|
|
|
34
34
|
- repo: https://github.com/rhysd/actionlint
|
|
35
|
-
rev: v1.7.
|
|
35
|
+
rev: v1.7.12
|
|
36
36
|
hooks:
|
|
37
37
|
- id: actionlint
|
|
38
38
|
|
|
39
|
-
- repo: https://github.com/
|
|
40
|
-
rev: v1.
|
|
39
|
+
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
|
40
|
+
rev: v1.23.1
|
|
41
41
|
hooks:
|
|
42
42
|
- id: zizmor
|
|
43
43
|
|
|
44
44
|
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
45
|
-
rev: v2.
|
|
45
|
+
rev: v2.21.0
|
|
46
46
|
hooks:
|
|
47
47
|
- id: pyproject-fmt
|
|
48
48
|
|
|
49
49
|
- repo: https://github.com/abravalheri/validate-pyproject
|
|
50
|
-
rev: v0.
|
|
50
|
+
rev: v0.25
|
|
51
51
|
hooks:
|
|
52
52
|
- id: validate-pyproject
|
|
53
|
+
additional_dependencies: ["trove-classifiers>=2026.6.1.19"]
|
|
53
54
|
|
|
54
55
|
- repo: https://github.com/tox-dev/tox-ini-fmt
|
|
55
|
-
rev: 1.
|
|
56
|
+
rev: 1.7.1
|
|
56
57
|
hooks:
|
|
57
58
|
- id: tox-ini-fmt
|
|
58
59
|
|
|
59
60
|
- repo: https://github.com/rbubley/mirrors-prettier
|
|
60
|
-
rev: v3.
|
|
61
|
+
rev: v3.8.1
|
|
61
62
|
hooks:
|
|
62
63
|
- id: prettier
|
|
63
64
|
args: [--prose-wrap=always, --print-width=88]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: prettytable
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.18.0
|
|
4
4
|
Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
|
|
5
5
|
Project-URL: Changelog, https://github.com/prettytable/prettytable/releases
|
|
6
6
|
Project-URL: Funding, https://tidelift.com/subscription/pkg/pypi-prettytable?utm_source=pypi-prettytable&utm_medium=pypi
|
|
@@ -18,16 +18,17 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.15
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.16
|
|
21
22
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
23
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
23
24
|
Classifier: Topic :: Text Processing
|
|
24
25
|
Classifier: Typing :: Typed
|
|
25
26
|
Requires-Python: >=3.10
|
|
26
|
-
Requires-Dist: wcwidth
|
|
27
|
+
Requires-Dist: wcwidth>=0.3.5
|
|
27
28
|
Provides-Extra: tests
|
|
28
|
-
Requires-Dist: pytest; extra == 'tests'
|
|
29
29
|
Requires-Dist: pytest-cov; extra == 'tests'
|
|
30
30
|
Requires-Dist: pytest-lazy-fixtures; extra == 'tests'
|
|
31
|
+
Requires-Dist: pytest>=9; extra == 'tests'
|
|
31
32
|
Description-Content-Type: text/markdown
|
|
32
33
|
|
|
33
34
|
# PrettyTable
|
|
@@ -61,11 +62,11 @@ PrettyTable lets you print tables in an attractive ASCII form:
|
|
|
61
62
|
|
|
62
63
|
Install via pip:
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
python3 -m pip install -U prettytable
|
|
65
66
|
|
|
66
67
|
Install latest development version:
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
python3 -m pip install -U git+https://github.com/prettytable/prettytable
|
|
69
70
|
|
|
70
71
|
Or from `requirements.txt`:
|
|
71
72
|
|
|
@@ -135,13 +136,10 @@ method, which takes two arguments - a string which is the name for the field the
|
|
|
135
136
|
you are adding corresponds to, and a list or tuple which contains the column data:
|
|
136
137
|
|
|
137
138
|
```python
|
|
138
|
-
table.add_column("City name",
|
|
139
|
-
["Adelaide","Brisbane","Darwin","Hobart","Sydney","Melbourne","Perth"])
|
|
139
|
+
table.add_column("City name", ["Adelaide", "Brisbane", "Darwin", "Hobart", "Sydney", "Melbourne", "Perth"])
|
|
140
140
|
table.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5386])
|
|
141
|
-
table.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092,
|
|
142
|
-
|
|
143
|
-
table.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9,
|
|
144
|
-
869.4])
|
|
141
|
+
table.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769])
|
|
142
|
+
table.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4])
|
|
145
143
|
```
|
|
146
144
|
|
|
147
145
|
#### Mixing and matching
|
|
@@ -255,6 +253,30 @@ def my_cli_function(table_format: str = 'text'):
|
|
|
255
253
|
print(table.get_formatted_string(table_format))
|
|
256
254
|
```
|
|
257
255
|
|
|
256
|
+
#### Paginating your table
|
|
257
|
+
|
|
258
|
+
If you have a large table and want to split it into multiple pages, you can use the
|
|
259
|
+
`paginate` method. This method splits the table into pages of a specified length and
|
|
260
|
+
separates them with a line break character (by default, a form feed character `\f`):
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
paginated_string = table.paginate(page_length=10)
|
|
264
|
+
print(paginated_string)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
The `page_length` parameter controls how many rows appear on each page (default: 58).
|
|
268
|
+
The `line_break` parameter specifies the string used to separate pages (default: `"\f"`
|
|
269
|
+
form feed). You can also pass any keyword arguments that are accepted by `get_string()`
|
|
270
|
+
to control the formatting of each page:
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
paginated_string = table.paginate(page_length=20, line_break="\n\n---\n\n", border=True)
|
|
274
|
+
print(paginated_string)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
This is particularly useful when printing large tables to a terminal or when you want to
|
|
278
|
+
format output for pagination in documents.
|
|
279
|
+
|
|
258
280
|
#### Controlling which data gets displayed
|
|
259
281
|
|
|
260
282
|
If you like, you can restrict the output of `print(table)` or `table.get_string` to only
|
|
@@ -497,6 +519,39 @@ to get a table like this:
|
|
|
497
519
|
|
|
498
520
|
Any added dividers will be removed if a table is sorted.
|
|
499
521
|
|
|
522
|
+
### Adding a title to your table
|
|
523
|
+
|
|
524
|
+
You can add a title to your table with the `title` attribute:
|
|
525
|
+
|
|
526
|
+
```python
|
|
527
|
+
table.title = "Australian Cities"
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
Titles can span multiple lines by including `\n` in the string:
|
|
531
|
+
|
|
532
|
+
```python
|
|
533
|
+
table.title = "Australian Cities\nPopulation Data"
|
|
534
|
+
print(table)
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
This produces:
|
|
538
|
+
|
|
539
|
+
```
|
|
540
|
+
+-------------------------------------------------+
|
|
541
|
+
| Australian Cities |
|
|
542
|
+
| Population Data |
|
|
543
|
+
+-----------+------+------------+-----------------+
|
|
544
|
+
| City name | Area | Population | Annual Rainfall |
|
|
545
|
+
+-----------+------+------------+-----------------+
|
|
546
|
+
| Adelaide | 1295 | 1158259 | 600.5 |
|
|
547
|
+
| Brisbane | 5905 | 1857594 | 1146.4 |
|
|
548
|
+
| Darwin | 112 | 120900 | 1714.7 |
|
|
549
|
+
+-----------+------+------------+-----------------+
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
Each line of the title is centered and bordered independently. Multiline titles also
|
|
553
|
+
work with HTML output (using `<br>` in the `<caption>` tag) and Markdown output.
|
|
554
|
+
|
|
500
555
|
### Changing the appearance of your table - the easy way
|
|
501
556
|
|
|
502
557
|
By default, PrettyTable produces ASCII tables that look like the ones used in SQL
|
|
@@ -525,6 +580,8 @@ In addition to `MARKDOWN` you can use these in-built styles:
|
|
|
525
580
|
- `MSWORD_FRIENDLY` - A format which works nicely with Microsoft Word's "Convert to
|
|
526
581
|
table" feature
|
|
527
582
|
- `ORGMODE` - A table style that fits [Org mode](https://orgmode.org/) syntax
|
|
583
|
+
- `RST` - A table style that produces reStructuredText
|
|
584
|
+
[grid tables](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#tables)
|
|
528
585
|
- `SINGLE_BORDER` and `DOUBLE_BORDER` - Styles that use continuous single/double border
|
|
529
586
|
lines with Box drawing characters for a fancier display on terminal
|
|
530
587
|
|
|
@@ -642,6 +699,36 @@ print(table.get_string(border=False))
|
|
|
642
699
|
print(table)
|
|
643
700
|
```
|
|
644
701
|
|
|
702
|
+
#### Custom format example (with _colors_)
|
|
703
|
+
|
|
704
|
+
The `custom_format` attribute allows you to define a function for custom cell value
|
|
705
|
+
formatting. For example, the following code demonstrates how to apply a single function
|
|
706
|
+
across all columns to display strings in `blue`, positive numbers in `green`, and
|
|
707
|
+
negative numbers in `red`, all with a precision of two decimal places. Your custom
|
|
708
|
+
function can also inspect the `field` parameter to apply field-specific formatting.
|
|
709
|
+
|
|
710
|
+
```python
|
|
711
|
+
from prettytable import PrettyTable
|
|
712
|
+
from typing import Any
|
|
713
|
+
from termcolor import colored
|
|
714
|
+
|
|
715
|
+
def _colored(field: str, val: Any) -> str:
|
|
716
|
+
if isinstance(val, (int, float)):
|
|
717
|
+
if val >= 0:
|
|
718
|
+
return colored(f"{val:.2f}", "green")
|
|
719
|
+
return colored(f"{val:.2f}", "red")
|
|
720
|
+
elif isinstance(val, str):
|
|
721
|
+
return colored(val, "blue")
|
|
722
|
+
return f"{val}"
|
|
723
|
+
|
|
724
|
+
table = PrettyTable(("Name", "Overtime"))
|
|
725
|
+
table.custom_format = _colored
|
|
726
|
+
|
|
727
|
+
for row in [["John Doe", 5.0], ["Jane Smith", -2.0]]:
|
|
728
|
+
table.add_row([row[0], row[1]])
|
|
729
|
+
print(table)
|
|
730
|
+
```
|
|
731
|
+
|
|
645
732
|
### Changing the appearance of your table - with _colors_!
|
|
646
733
|
|
|
647
734
|
PrettyTable has the functionality of printing your table with ANSI color codes. This
|
|
@@ -806,10 +893,18 @@ new_table = old_table[0:5]
|
|
|
806
893
|
|
|
807
894
|
## Contributing
|
|
808
895
|
|
|
809
|
-
After editing files, use
|
|
896
|
+
After editing files, use at least [Black](https://github.com/psf/black) to auto-format
|
|
810
897
|
changed lines.
|
|
811
898
|
|
|
812
899
|
```sh
|
|
813
|
-
|
|
814
|
-
black
|
|
900
|
+
python3 -m pip install black
|
|
901
|
+
black .
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
To run all pre-commit checks, linters, formatters (including Black), and tests use
|
|
905
|
+
[tox](https://github.com/tox-dev/tox):
|
|
906
|
+
|
|
907
|
+
```sh
|
|
908
|
+
python3 -m pip install tox
|
|
909
|
+
tox
|
|
815
910
|
```
|
|
@@ -29,11 +29,11 @@ PrettyTable lets you print tables in an attractive ASCII form:
|
|
|
29
29
|
|
|
30
30
|
Install via pip:
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
python3 -m pip install -U prettytable
|
|
33
33
|
|
|
34
34
|
Install latest development version:
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
python3 -m pip install -U git+https://github.com/prettytable/prettytable
|
|
37
37
|
|
|
38
38
|
Or from `requirements.txt`:
|
|
39
39
|
|
|
@@ -103,13 +103,10 @@ method, which takes two arguments - a string which is the name for the field the
|
|
|
103
103
|
you are adding corresponds to, and a list or tuple which contains the column data:
|
|
104
104
|
|
|
105
105
|
```python
|
|
106
|
-
table.add_column("City name",
|
|
107
|
-
["Adelaide","Brisbane","Darwin","Hobart","Sydney","Melbourne","Perth"])
|
|
106
|
+
table.add_column("City name", ["Adelaide", "Brisbane", "Darwin", "Hobart", "Sydney", "Melbourne", "Perth"])
|
|
108
107
|
table.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5386])
|
|
109
|
-
table.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092,
|
|
110
|
-
|
|
111
|
-
table.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9,
|
|
112
|
-
869.4])
|
|
108
|
+
table.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769])
|
|
109
|
+
table.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4])
|
|
113
110
|
```
|
|
114
111
|
|
|
115
112
|
#### Mixing and matching
|
|
@@ -223,6 +220,30 @@ def my_cli_function(table_format: str = 'text'):
|
|
|
223
220
|
print(table.get_formatted_string(table_format))
|
|
224
221
|
```
|
|
225
222
|
|
|
223
|
+
#### Paginating your table
|
|
224
|
+
|
|
225
|
+
If you have a large table and want to split it into multiple pages, you can use the
|
|
226
|
+
`paginate` method. This method splits the table into pages of a specified length and
|
|
227
|
+
separates them with a line break character (by default, a form feed character `\f`):
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
paginated_string = table.paginate(page_length=10)
|
|
231
|
+
print(paginated_string)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The `page_length` parameter controls how many rows appear on each page (default: 58).
|
|
235
|
+
The `line_break` parameter specifies the string used to separate pages (default: `"\f"`
|
|
236
|
+
form feed). You can also pass any keyword arguments that are accepted by `get_string()`
|
|
237
|
+
to control the formatting of each page:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
paginated_string = table.paginate(page_length=20, line_break="\n\n---\n\n", border=True)
|
|
241
|
+
print(paginated_string)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
This is particularly useful when printing large tables to a terminal or when you want to
|
|
245
|
+
format output for pagination in documents.
|
|
246
|
+
|
|
226
247
|
#### Controlling which data gets displayed
|
|
227
248
|
|
|
228
249
|
If you like, you can restrict the output of `print(table)` or `table.get_string` to only
|
|
@@ -465,6 +486,39 @@ to get a table like this:
|
|
|
465
486
|
|
|
466
487
|
Any added dividers will be removed if a table is sorted.
|
|
467
488
|
|
|
489
|
+
### Adding a title to your table
|
|
490
|
+
|
|
491
|
+
You can add a title to your table with the `title` attribute:
|
|
492
|
+
|
|
493
|
+
```python
|
|
494
|
+
table.title = "Australian Cities"
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
Titles can span multiple lines by including `\n` in the string:
|
|
498
|
+
|
|
499
|
+
```python
|
|
500
|
+
table.title = "Australian Cities\nPopulation Data"
|
|
501
|
+
print(table)
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
This produces:
|
|
505
|
+
|
|
506
|
+
```
|
|
507
|
+
+-------------------------------------------------+
|
|
508
|
+
| Australian Cities |
|
|
509
|
+
| Population Data |
|
|
510
|
+
+-----------+------+------------+-----------------+
|
|
511
|
+
| City name | Area | Population | Annual Rainfall |
|
|
512
|
+
+-----------+------+------------+-----------------+
|
|
513
|
+
| Adelaide | 1295 | 1158259 | 600.5 |
|
|
514
|
+
| Brisbane | 5905 | 1857594 | 1146.4 |
|
|
515
|
+
| Darwin | 112 | 120900 | 1714.7 |
|
|
516
|
+
+-----------+------+------------+-----------------+
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Each line of the title is centered and bordered independently. Multiline titles also
|
|
520
|
+
work with HTML output (using `<br>` in the `<caption>` tag) and Markdown output.
|
|
521
|
+
|
|
468
522
|
### Changing the appearance of your table - the easy way
|
|
469
523
|
|
|
470
524
|
By default, PrettyTable produces ASCII tables that look like the ones used in SQL
|
|
@@ -493,6 +547,8 @@ In addition to `MARKDOWN` you can use these in-built styles:
|
|
|
493
547
|
- `MSWORD_FRIENDLY` - A format which works nicely with Microsoft Word's "Convert to
|
|
494
548
|
table" feature
|
|
495
549
|
- `ORGMODE` - A table style that fits [Org mode](https://orgmode.org/) syntax
|
|
550
|
+
- `RST` - A table style that produces reStructuredText
|
|
551
|
+
[grid tables](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#tables)
|
|
496
552
|
- `SINGLE_BORDER` and `DOUBLE_BORDER` - Styles that use continuous single/double border
|
|
497
553
|
lines with Box drawing characters for a fancier display on terminal
|
|
498
554
|
|
|
@@ -610,6 +666,36 @@ print(table.get_string(border=False))
|
|
|
610
666
|
print(table)
|
|
611
667
|
```
|
|
612
668
|
|
|
669
|
+
#### Custom format example (with _colors_)
|
|
670
|
+
|
|
671
|
+
The `custom_format` attribute allows you to define a function for custom cell value
|
|
672
|
+
formatting. For example, the following code demonstrates how to apply a single function
|
|
673
|
+
across all columns to display strings in `blue`, positive numbers in `green`, and
|
|
674
|
+
negative numbers in `red`, all with a precision of two decimal places. Your custom
|
|
675
|
+
function can also inspect the `field` parameter to apply field-specific formatting.
|
|
676
|
+
|
|
677
|
+
```python
|
|
678
|
+
from prettytable import PrettyTable
|
|
679
|
+
from typing import Any
|
|
680
|
+
from termcolor import colored
|
|
681
|
+
|
|
682
|
+
def _colored(field: str, val: Any) -> str:
|
|
683
|
+
if isinstance(val, (int, float)):
|
|
684
|
+
if val >= 0:
|
|
685
|
+
return colored(f"{val:.2f}", "green")
|
|
686
|
+
return colored(f"{val:.2f}", "red")
|
|
687
|
+
elif isinstance(val, str):
|
|
688
|
+
return colored(val, "blue")
|
|
689
|
+
return f"{val}"
|
|
690
|
+
|
|
691
|
+
table = PrettyTable(("Name", "Overtime"))
|
|
692
|
+
table.custom_format = _colored
|
|
693
|
+
|
|
694
|
+
for row in [["John Doe", 5.0], ["Jane Smith", -2.0]]:
|
|
695
|
+
table.add_row([row[0], row[1]])
|
|
696
|
+
print(table)
|
|
697
|
+
```
|
|
698
|
+
|
|
613
699
|
### Changing the appearance of your table - with _colors_!
|
|
614
700
|
|
|
615
701
|
PrettyTable has the functionality of printing your table with ANSI color codes. This
|
|
@@ -774,10 +860,18 @@ new_table = old_table[0:5]
|
|
|
774
860
|
|
|
775
861
|
## Contributing
|
|
776
862
|
|
|
777
|
-
After editing files, use
|
|
863
|
+
After editing files, use at least [Black](https://github.com/psf/black) to auto-format
|
|
778
864
|
changed lines.
|
|
779
865
|
|
|
780
866
|
```sh
|
|
781
|
-
|
|
782
|
-
black
|
|
867
|
+
python3 -m pip install black
|
|
868
|
+
black .
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
To run all pre-commit checks, linters, formatters (including Black), and tests use
|
|
872
|
+
[tox](https://github.com/tox-dev/tox):
|
|
873
|
+
|
|
874
|
+
```sh
|
|
875
|
+
python3 -m pip install tox
|
|
876
|
+
tox
|
|
783
877
|
```
|