From 06d351f054d5fc5a55027629d18a01050f0d1ec0 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 27 Jun 2018 15:38:42 +0100 Subject: [PATCH] utils/misc: fix write_table column widths Consider headers when calculating column widths. This will ensure proper alignment in cases where the column header is wider than any of the column values. --- wa/utils/misc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wa/utils/misc.py b/wa/utils/misc.py index bb9ab546..2090c24a 100644 --- a/wa/utils/misc.py +++ b/wa/utils/misc.py @@ -110,6 +110,8 @@ def write_table(rows, wfh, align='>', headers=None): # pylint: disable=R0914 cols = list(zip(*rows)) col_widths = [max(list(map(len, c))) for c in cols] + if headers: + col_widths = [max([c, len(h)]) for c, h in zip(col_widths, headers)] row_format = ' '.join(['{:%s%s}' % (align[i], w) for i, w in enumerate(col_widths)]) row_format += '\n'