From 5d9648779fc1d553d0922ef5730ac87e57ec801c Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Wed, 11 Feb 2026 19:23:17 +0100 Subject: [PATCH] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20README.md?= =?UTF-8?q?=20=09ge=C3=A4ndert:=20=20=20=20=20=20=20pyproject.toml=20=09ge?= =?UTF-8?q?=C3=A4ndert:=20=20=20=20=20=20=20src/text=5Ftable/=5Fcore.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ pyproject.toml | 2 +- src/text_table/_core.py | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78b3246..3b6c06e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ pip install text-table --index-url https://jcloud-services.ddns.net/simple/ ## Changelog +### Version 0.1.4 +- Better handling of empty tables + ### Version 0.1.3 - Added support for objects with custom length and correct formatting of these diff --git a/pyproject.toml b/pyproject.toml index 2e0f45a..514636a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,6 @@ build-backend = "setuptools.build_meta" [project] name = "text_table" -version = "0.1.3" +version = "0.1.4" description = "A simple library for creating text tables." readme = "README.md" \ No newline at end of file diff --git a/src/text_table/_core.py b/src/text_table/_core.py index 6e0cac3..d99c94a 100644 --- a/src/text_table/_core.py +++ b/src/text_table/_core.py @@ -115,6 +115,13 @@ def table(data: Sequence[dict], *, borders: bool = False, border_charset: TableB :rtype: str ''' + any_content = False + for col in data: + if col: + any_content = True + if not any_content: + return '' + column_widths = _get_max_widths(data) columns = list(column_widths.keys()) table = f'''{(column_space * ' ').join([(c.upper() if uppercase_column_headers else c) + ' ' * (column_widths[c] - len(c)) for c in columns])}'''