@@ -56,11 +56,13 @@ def __init__(
56
56
for i in range (len (options .column_widths )):
57
57
option = options .column_widths [i ]
58
58
minimum = self .__column_widths [i ]
59
- if option < minimum :
59
+ if option is None :
60
+ option = minimum
61
+ elif option < minimum :
60
62
raise ValueError (
61
63
f"The value at index { i } of `column_widths` is { option } which is less than the minimum { minimum } ."
62
64
)
63
- self .__column_widths = options . column_widths
65
+ self .__column_widths [ i ] = option
64
66
65
67
self .__alignments = options .alignments or [Alignment .CENTER ] * self .__columns
66
68
@@ -314,25 +316,35 @@ def table2ascii(
314
316
* ,
315
317
first_col_heading : bool = False ,
316
318
last_col_heading : bool = False ,
317
- column_widths : Optional [List [int ]] = None ,
319
+ column_widths : Optional [List [Optional [ int ] ]] = None ,
318
320
alignments : Optional [List [Alignment ]] = None ,
319
321
style : TableStyle = PresetStyle .double_thin_compact ,
320
322
) -> str :
321
323
"""
322
324
Convert a 2D Python table to ASCII text
323
325
324
326
Args:
325
- header (:class:`Optional[List[Any]]`): List of column values in the table's header row
326
- body (:class:`Optional[List[List[Any]]]`): 2-dimensional list of values in the table's body
327
- footer (:class:`Optional[List[Any]]`): List of column values in the table's footer row
328
- first_col_heading (:class:`bool`): Whether to add a header column separator after the first column
329
- last_col_heading (:class:`bool`): Whether to add a header column separator before the last column
330
- column_widths (:class:`Optional[List[int]]`): List of widths in characters for each column (``None`` for auto-sizing)
331
- alignments (:class:`List[Alignment]`): List of alignments (ex. `[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]`)
332
- style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported)
327
+ header (Optional[List[Any]]): List of column values in the table's header row.
328
+ If not specified, the table will not have a header row.
329
+ body (Optional[List[List[Any]]]): 2-dimensional list of values in the table's body.
330
+ If not specified, the table will not have a body.
331
+ footer (Optional[List[Any]]): List of column values in the table's footer row.
332
+ If not specified, the table will not have a footer row.
333
+ first_col_heading (:class:`bool`): Whether to add a header column separator after the first
334
+ column. Defaults to ``False``.
335
+ last_col_heading (:class:`bool`): Whether to add a header column separator before the last
336
+ column. Defaults to ``False``.
337
+ column_widths (Optional[List[Optional[:class:`int`]]]): List of widths in characters for each
338
+ column. Any value of ``None`` indicates that the column width should be determined automatically.
339
+ If ``column_widths`` is set to ``None``, all columns will be automatically sized. Defaults to ``None``.
340
+ alignments (Optional[List[:class:`Alignment`]]): List of alignments for each column
341
+ (ex. ``[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]``). If not specified or set to ``None``,
342
+ all columns will be center-aligned. Defaults to ``None``.
343
+ style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported).
344
+ Defaults to :data:`PresetStyle.double_thin_compact`.
333
345
334
346
Returns:
335
- str: The generated ASCII table
347
+ :class:` str` : The generated ASCII table
336
348
"""
337
349
return TableToAscii (
338
350
header ,
0 commit comments