geändert: src/text_table/_core.py
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Sequence
|
||||
|
||||
__all__ = [
|
||||
'TableBorderCharset',
|
||||
'BORDER_THIN',
|
||||
@@ -81,19 +83,18 @@ BORDER_ROUND = TableBorderCharset(
|
||||
'┼'
|
||||
)
|
||||
|
||||
def _get_max_widths(data: dict) -> dict:
|
||||
def _get_max_widths(data: Sequence[dict]) -> dict:
|
||||
max_widths = {}
|
||||
for row in data:
|
||||
for col in row:
|
||||
max_widths[col] = max(len(str(row[col])), max_widths.get(col, 0))
|
||||
return max_widths
|
||||
|
||||
def table(data: dict, *, borders: bool = False, border_charset: TableBorderCharset = BORDER_THIN, column_space: int = 1, uppercase_column_headers: bool = True) -> str:
|
||||
def table(data: Sequence[dict], *, borders: bool = False, border_charset: TableBorderCharset = BORDER_THIN, column_space: int = 1, uppercase_column_headers: bool = True) -> str:
|
||||
'''
|
||||
Creates a text table.
|
||||
|
||||
:param data: The data.
|
||||
:type data: dict
|
||||
:param borders: If True, the table will have borders, otherwise it will not have any borders.
|
||||
:type borders: bool
|
||||
:param border_charset: The charset for the borders.
|
||||
@@ -130,7 +131,6 @@ def table(data: dict, *, borders: bool = False, border_charset: TableBorderChars
|
||||
table += border_charset.line_vertical + ' '
|
||||
if borders:
|
||||
table_without_borders = table
|
||||
table_width = max([len(r) for r in table_without_borders.split('\n')])
|
||||
table = border_charset.corner_top_left
|
||||
for col in columns:
|
||||
table += border_charset.line_horizontal * (column_widths[col] + 2)
|
||||
|
||||
Reference in New Issue
Block a user