How to use the tabulate._align_column function in tabulate

To help you get started, we’ve selected a few tabulate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astanin / python-tabulate / test / test_internal.py View on Github external
def test_align_column_none():
    "Internal: _align_column(..., None)"
    column = ["123.4", "56.7890"]
    output = T._align_column(column, None)
    expected = ["123.4", "56.7890"]
    assert_equal(output, expected)
github astanin / python-tabulate / test / test_internal.py View on Github external
def test_align_column_decimal():
    "Internal: _align_column(..., 'decimal')"
    column = ["12.345", "-1234.5", "1.23", "1234.5", "1e+234", "1.0e234"]
    output = T._align_column(column, "decimal")
    expected = [
        "   12.345  ",
        "-1234.5    ",
        "    1.23   ",
        " 1234.5    ",
        "    1e+234 ",
        "    1.0e234",
    ]
    assert_equal(output, expected)
github astanin / python-tabulate / test / test_internal.py View on Github external
def test_align_column_multiline():
    "Internal: _align_column(..., is_multiline=True)"
    column = ["1", "123", "12345\n6"]
    output = T._align_column(column, "center", is_multiline=True)
    expected = ["  1  ", " 123 ", "12345" + "\n" + "  6  "]
    assert_equal(output, expected)
github merenlab / anvio / anvio / terminal.py View on Github external
else:
                lines = [line.splitlines() for line in strings]
                lines_pad = [[(s, maxwidth + len(s) - width_fn(s)) for s in group]
                             for group in lines]
                padded_strings = ["\n".join([padfn(w, s) for s, w in group])
                                  for group in lines_pad]
        else:
            if not enable_widechars and not has_invisible:
                padded_strings = [padfn(maxwidth, s) for s in strings]
            else:
                s_lens = list(map(len, strings))
                visible_widths = [maxwidth - (w - l) for w, l in zip(s_widths, s_lens)]
                padded_strings = [padfn(w, s) for s, w in zip(strings, visible_widths)]
        return padded_strings

    tabulate._align_column = _align_column
    return tabulate.tabulate(*args, **kwargs)