Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2262,18 +2262,24 @@ def tabulate(
)

if maxheadercolwidths is not None:
num_cols = len(list_of_lists[0])
if isinstance(maxheadercolwidths, int): # Expand scalar for all columns
maxheadercolwidths = _expand_iterable(
maxheadercolwidths, num_cols, maxheadercolwidths
)
else: # Ignore col width for any 'trailing' columns
maxheadercolwidths = _expand_iterable(maxheadercolwidths, num_cols, None)
if len(list_of_lists):
num_cols = len(list_of_lists[0])
elif len(headers):
num_cols = len(headers)
else:
num_cols = 0
if num_cols:
if isinstance(maxheadercolwidths, int): # Expand scalar for all columns
maxheadercolwidths = _expand_iterable(
maxheadercolwidths, num_cols, maxheadercolwidths
)
else: # Ignore col width for any 'trailing' columns
maxheadercolwidths = _expand_iterable(maxheadercolwidths, num_cols, None)

numparses = _expand_numparse(disable_numparse, num_cols)
headers = _wrap_text_to_colwidths(
[headers], maxheadercolwidths, numparses=numparses, break_long_words=break_long_words, break_on_hyphens=break_on_hyphens
)[0]
numparses = _expand_numparse(disable_numparse, num_cols)
headers = _wrap_text_to_colwidths(
[headers], maxheadercolwidths, numparses=numparses, break_long_words=break_long_words, break_on_hyphens=break_on_hyphens
)[0]

# empty values in the first column of RST tables should be escaped (issue #82)
# "" should be escaped as "\\ " or ".."
Expand Down