Skip to content

Commit c4d2e2c

Browse files
Andrew Gaulastanin
Andrew Gaul
authored andcommitted
Merged in andrewgaul/python-tabulate/colalign (pull request astanin#51)
Rename alignfmt to colalign
2 parents ed3702d + 20fdaa9 commit c4d2e2c

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@ Custom column alignment
421421
~~~~~~~~~~~~~~~~~~~~~~~
422422

423423
``tabulate`` allows a custom column alignment to override the above. The
424-
``alignfmt`` argument can be a list or a tuple of ``stralign`` named arguments.
424+
``colalign`` argument can be a list or a tuple of ``stralign`` named arguments.
425425
Possible column alignments are: ``right``, ``center``, ``left``, ``decimal``
426426
(only for numbers), and ``None`` (to disable alignment). Omitting an alignment
427427
uses the default. For example::
428428

429-
>>> print(tabulate([["one", "two"], ["three", "four"]], alignfmt=("right",))
429+
>>> print(tabulate([["one", "two"], ["three", "four"]], colalign=("right",))
430430
----- ----
431431
one two
432432
three four

tabulate.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
960960
def tabulate(tabular_data, headers=(), tablefmt="simple",
961961
floatfmt=_DEFAULT_FLOATFMT, numalign="decimal", stralign="left",
962962
missingval=_DEFAULT_MISSINGVAL, showindex="default", disable_numparse=False,
963-
alignfmt=None):
963+
colalign=None):
964964
"""Format a fixed width table for pretty printing.
965965
966966
>>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
@@ -1289,9 +1289,9 @@ def tabulate(tabular_data, headers=(), tablefmt="simple",
12891289

12901290
# align columns
12911291
aligns = [numalign if ct in [int,float] else stralign for ct in coltypes]
1292-
if alignfmt is not None:
1293-
assert isinstance(alignfmt, Iterable)
1294-
for idx, align in enumerate(alignfmt):
1292+
if colalign is not None:
1293+
assert isinstance(colalign, Iterable)
1294+
for idx, align in enumerate(colalign):
12951295
aligns[idx] = align
12961296
minwidths = [width_fn(h) + MIN_PADDING for h in headers] if headers else [0]*len(cols)
12971297
cols = [_align_column(c, a, minw, has_invisible, enable_widechars, is_multiline)
@@ -1476,7 +1476,7 @@ def _main():
14761476
sys.exit(2)
14771477
headers = []
14781478
floatfmt = _DEFAULT_FLOATFMT
1479-
alignfmt = None
1479+
colalign = None
14801480
tablefmt = "simple"
14811481
sep = r"\s+"
14821482
outfile = "-"
@@ -1487,8 +1487,8 @@ def _main():
14871487
outfile = value
14881488
elif opt in ["-F", "--float"]:
14891489
floatfmt = value
1490-
elif opt in ["-A", "--align"]:
1491-
alignfmt = value.split()
1490+
elif opt in ["-C", "--colalign"]:
1491+
colalign = value.split()
14921492
elif opt in ["-f", "--format"]:
14931493
if value not in tabulate_formats:
14941494
print("%s is not a supported table format" % value)
@@ -1508,19 +1508,19 @@ def _main():
15081508
if _is_file(f):
15091509
_pprint_file(f, headers=headers, tablefmt=tablefmt,
15101510
sep=sep, floatfmt=floatfmt, file=out,
1511-
alignfmt=alignfmt)
1511+
colalign=colalign)
15121512
else:
15131513
with open(f) as fobj:
15141514
_pprint_file(fobj, headers=headers, tablefmt=tablefmt,
15151515
sep=sep, floatfmt=floatfmt, file=out,
1516-
alignfmt=alignfmt)
1516+
colalign=colalign)
15171517

15181518

1519-
def _pprint_file(fobject, headers, tablefmt, sep, floatfmt, file, alignfmt):
1519+
def _pprint_file(fobject, headers, tablefmt, sep, floatfmt, file, colalign):
15201520
rows = fobject.readlines()
15211521
table = [re.split(sep, r.rstrip()) for r in rows if r.strip()]
15221522
print(tabulate(table, headers, tablefmt, floatfmt=floatfmt,
1523-
alignfmt=alignfmt), file=file)
1523+
colalign=colalign), file=file)
15241524

15251525

15261526
if __name__ == "__main__":

test/test_output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ def test_floatfmt_multi():
936936
expected = '0.1 0.123 0.12345'
937937
assert_equal(expected, result)
938938

939-
def test_alignfmt_multi():
940-
"Output: string columns with custom alignfmt"
941-
result = tabulate([["one", "two"], ["three", "four"]], alignfmt=("right",), tablefmt="plain")
939+
def test_colalign_multi():
940+
"Output: string columns with custom colalign"
941+
result = tabulate([["one", "two"], ["three", "four"]], colalign=("right",), tablefmt="plain")
942942
expected = ' one two\nthree four'
943943
assert_equal(expected, result)
944944

0 commit comments

Comments
 (0)