How to use the pytablewriter.style.Align.RIGHT function in pytablewriter

To help you get started, we’ve selected a few pytablewriter 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 thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
"""\
            # auto align
            |left|   right   |   center   |auto|auto|   None    |
            |---:|-----------|------------|---:|----|-----------|
            |   0|r          |center align|   0|a   |n          |
            |  11|right align|bb          |  11|auto|none (auto)|
            """
        )
        out = writer.dumps()
        print_test_result(expected=expected, actual=out)
        assert out == expected

        writer.table_name = "specify alignment for each column manually"
        writer.styles = [
            Style(align=Align.LEFT),
            Style(align=Align.RIGHT),
            Style(align=Align.CENTER),
            Style(align=Align.AUTO),
            Style(align=Align.AUTO),
            None,
        ]
        expected = dedent(
            """\
            # specify alignment for each column manually
            |left|   right   |   center   |auto|auto|   None    |
            |----|----------:|:----------:|---:|----|-----------|
            |0   |          r|center align|   0|a   |n          |
            |11  |right align|     bb     |  11|auto|none (auto)|
            """
        )
        out = writer.dumps()
        print_test_result(expected=expected, actual=out)
github thombashi / pytablewriter / test / test_style.py View on Github external
                    "align": Align.RIGHT,
                    "font_size": FontSize.TINY,
                    "font_weight": FontWeight.BOLD,
                    "thousand_separator": ThousandSeparator.SPACE,
                },
                {
                    "align": Align.RIGHT,
                    "font_size": FontSize.TINY,
                    "font_weight": FontWeight.BOLD,
                    "thousand_separator": ThousandSeparator.SPACE,
                },
            ],
            [
                {
                    "align": "left",
                    "font_size": "small",
                    "font_weight": "bold",
github thombashi / pytablewriter / test / test_style.py View on Github external
            [Style(align=Align.RIGHT), Style(align="right"), True],
            [Style(align=Align.RIGHT), Style(align=Align.RIGHT, font_size=FontSize.TINY), False],
            [Style(font_size=FontSize.TINY), Style(font_size=FontSize.TINY), True],
            [Style(font_size=FontSize.TINY), Style(font_size="tiny"), True],
            [Style(font_size=FontSize.TINY), Style(font_size=FontSize.LARGE), False],
            [Style(font_weight="bold"), Style(font_weight=FontWeight.BOLD), True],
            [Style(font_weight="bold"), Style(font_weight="normal"), False],
            [Style(font_style="italic"), Style(font_style=FontStyle.ITALIC), True],
            [Style(font_style="italic"), Style(font_style="normal"), False],
            [Style(thousand_separator=","), Style(thousand_separator=","), True],
            [Style(thousand_separator=","), Style(thousand_separator="comma"), True],
            [Style(thousand_separator=""), Style(thousand_separator=","), False],
            [
                Style(thousand_separator=ThousandSeparator.COMMA),
                Style(thousand_separator=ThousandSeparator.COMMA),
                True,
            ],
github thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
expected = dedent(
            """\
            # specify alignment for each column manually
            |left|   right   |   center   |auto|auto|   None    |
            |----|----------:|:----------:|---:|----|-----------|
            |0   |          r|center align|   0|a   |n          |
            |11  |right align|     bb     |  11|auto|none (auto)|
            """
        )
        out = writer.dumps()
        print_test_result(expected=expected, actual=out)
        assert out == expected

        # test for backward compatibility
        writer.styles = None
        writer.align_list = [Align.LEFT, Align.RIGHT, Align.CENTER, Align.AUTO, Align.AUTO, None]
        out = writer.dumps()
        print_test_result(expected=expected, actual=out)
        assert out == expected
github thombashi / pytablewriter / pytablewriter / writer / text / _markdown.py View on Github external
def _get_header_row_separator_items(self):
        header_separator_list = []
        for col_dp in self._column_dp_list:
            padding_len = self._get_padding_len(col_dp) + self.margin * 2
            align = self._get_align(col_dp.column_index, col_dp.align)

            if align == Align.RIGHT:
                separator_item = "-" * (padding_len - 1) + ":"
            elif align == Align.CENTER:
                separator_item = ":" + "-" * (padding_len - 2) + ":"
            else:
                separator_item = "-" * padding_len

            header_separator_list.append(separator_item)

        return header_separator_list
github thombashi / pytablewriter / pytablewriter / writer / _table_writer.py View on Github external
self._is_require_table_name = False
        self._is_require_header = False

        self.__line_break_handling = None
        self.line_break_handling = LineBreakHandling.NOP

        self.iteration_length = -1
        self.write_callback = lambda _iter_count, _iter_length: None  # NOP
        self._iter_count = None

        self.__align_list = []
        self.__align_char_mapping = {
            Align.AUTO: "<",
            Align.LEFT: "<",
            Align.RIGHT: ">",
            Align.CENTER: "^",
        }

        self.__style_list = []

        self.__clear_preprocess()
github hugovk / pypistats / src / pypistats / __init__.py View on Github external
writer.header_list = header_list

    # Custom alignment and format
    if header_list[0] in ["last_day", "last_month", "last_week"]:
        # Special case for 'recent'
        writer.style_list = len(header_list) * [Style(thousand_separator=",")]
    else:
        style_list = []
        type_hints = []

        for item in header_list:
            align = None
            thousand_separator = None
            type_hint = None
            if item == "percent":
                align = Align.RIGHT
            elif item == "downloads":
                thousand_separator = ","
            elif item == "category":
                type_hint = String
            style = Style(align=align, thousand_separator=thousand_separator)
            style_list.append(style)
            type_hints.append(type_hint)

        writer.style_list = style_list
        writer.type_hints = type_hints

    return writer.dumps()
github thombashi / pytablewriter / pytablewriter / writer / text / _latex.py View on Github external
def _get_col_align_char_list(self):
        col_align_list = []

        for col_dp in self._column_dp_list:
            align = self._get_style_attr_from_style(col_dp.column_index, "align")
            if align is None or align == Align.AUTO:
                align = col_dp.align

            if align == Align.RIGHT:
                col_align = "r"
            elif align == Align.CENTER:
                col_align = "c"
            else:
                col_align = "l"

            col_align_list.append(col_align)

        return col_align_list