How to use the pytablewriter.style.ThousandSeparator 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 / test_style.py View on Github external
                Style(thousand_separator=ThousandSeparator.SPACE),
                True,
            ],
            [
                Style(thousand_separator=ThousandSeparator.COMMA),
                Style(thousand_separator=ThousandSeparator.COMMA, font_size=FontSize.TINY),
                False,
            ],
            [
                Style(
                    align=Align.LEFT,
                    font_size=FontSize.TINY,
                    font_style=FontStyle.ITALIC,
                    font_weight=FontWeight.BOLD,
                    thousand_separator=ThousandSeparator.COMMA,
                ),
                Style(
github thombashi / pytablewriter / test / test_style.py View on Github external
                Style(thousand_separator=ThousandSeparator.COMMA),
                True,
            ],
            [
                Style(thousand_separator="space"),
                Style(thousand_separator=ThousandSeparator.SPACE),
                True,
            ],
            [
                Style(thousand_separator=ThousandSeparator.COMMA),
                Style(thousand_separator=ThousandSeparator.COMMA, font_size=FontSize.TINY),
                False,
            ],
            [
                Style(
                    align=Align.LEFT,
                    font_size=FontSize.TINY,
github thombashi / pytablewriter / test / test_style.py View on Github external
                    "thousand_separator": ThousandSeparator.NONE,
                },
            ],
        ],
    )
    def test_normal(self, value, expected):
        style = Style(**value)

        print("expected: {}\nactual: {}".format(expected, style), file=sys.stderr)

        assert style.align is expected.get("align")
        assert style.font_size is expected.get("font_size")
        assert style.font_weight is expected.get("font_weight")
        assert style.thousand_separator is expected.get("thousand_separator")
github thombashi / pytablewriter / test / test_style.py View on Github external
                    "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",
                    "thousand_separator": ",",
                },
                {
github thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
writer.from_tabledata(
            TableData(
                "",
                ["none_format", "thousand_separator_i", "thousand_separator_f", "f", "wo_f"],
                [
                    [1000, 1234567, 1234567.8, 1234.5678, 1234567.8],
                    [1000, 1234567, 1234567.8, 1234.5678, 1234567.8],
                ],
            )
        )

        writer.styles = [
            Style(thousand_separator=ThousandSeparator.NONE),
            Style(thousand_separator=ThousandSeparator.COMMA),
            Style(thousand_separator=ThousandSeparator.COMMA),
            Style(thousand_separator=ThousandSeparator.SPACE),
        ]
        out = writer.dumps()
        expected = dedent(
            """\
            |none_format|thousand_separator_i|thousand_separator_f|   f   |  wo_f   |
            |----------:|-------------------:|-------------------:|------:|--------:|
            |       1000|           1,234,567|         1,234,567.8|1 234.6|1234567.8|
            |       1000|           1,234,567|         1,234,567.8|1 234.6|1234567.8|
            """
        )
        print_test_result(expected=expected, actual=out)
        assert out == expected

        writer.styles = None
        writer.format_list = [
            ptw.Format.NONE,
github thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
def test_normal_style_thousand_separator(self, capsys):
        writer = table_writer_class()
        writer.from_tabledata(
            TableData(
                "",
                ["none_format", "thousand_separator_i", "thousand_separator_f", "f", "wo_f"],
                [
                    [1000, 1234567, 1234567.8, 1234.5678, 1234567.8],
                    [1000, 1234567, 1234567.8, 1234.5678, 1234567.8],
                ],
            )
        )

        writer.styles = [
            Style(thousand_separator=ThousandSeparator.NONE),
            Style(thousand_separator=ThousandSeparator.COMMA),
            Style(thousand_separator=ThousandSeparator.COMMA),
            Style(thousand_separator=ThousandSeparator.SPACE),
        ]
        out = writer.dumps()
        expected = dedent(
            """\
            |none_format|thousand_separator_i|thousand_separator_f|   f   |  wo_f   |
            |----------:|-------------------:|-------------------:|------:|--------:|
            |       1000|           1,234,567|         1,234,567.8|1 234.6|1234567.8|
            |       1000|           1,234,567|         1,234,567.8|1 234.6|1234567.8|
            """
        )
        print_test_result(expected=expected, actual=out)
        assert out == expected
github thombashi / pytablewriter / pytablewriter / writer / _table_writer.py View on Github external
def __get_thousand_separator(self, col_idx):
        thousand_separator = self._get_style_attr_from_style(col_idx, "thousand_separator")

        if not thousand_separator:
            try:
                thousand_separator = self.format_list[col_idx]
            except (IndexError, KeyError):
                pass

            if thousand_separator == Format.NONE:
                return ThousandSeparator.NONE
            elif thousand_separator == Format.THOUSAND_SEPARATOR:
                return ThousandSeparator.COMMA

        if thousand_separator is None:
            return ThousandSeparator.NONE

        return thousand_separator
github thombashi / pytablewriter / pytablewriter / writer / _table_writer.py View on Github external
from .._function import normalize_enum
from .._logger import WriterLogger
from ..error import (
    EmptyHeaderError,
    EmptyTableDataError,
    EmptyTableNameError,
    EmptyValueError,
    NotSupportedError,
)
from ..style import Align, NullStyler, Style, ThousandSeparator
from ._interface import TableWriterInterface


_ts_to_flag = {
    ThousandSeparator.NONE: Format.NONE,
    ThousandSeparator.COMMA: Format.THOUSAND_SEPARATOR,
    ThousandSeparator.SPACE: Format.THOUSAND_SEPARATOR,
}


class AbstractTableWriter(TableWriterInterface):
    """
    An abstract base class of table writer classes.

    .. py:attribute:: stream

        Stream to write tables.
        You can use arbitrary stream which supported ``write`` method
        such as ``sys.stdout``, file stream, ``StringIO``, and so forth.
        Defaults to ``sys.stdout``.
github thombashi / pytablewriter / pytablewriter / writer / _table_writer.py View on Github external
def __get_thousand_separator(self, col_idx):
        thousand_separator = self._get_style_attr_from_style(col_idx, "thousand_separator")

        if not thousand_separator:
            try:
                thousand_separator = self.format_list[col_idx]
            except (IndexError, KeyError):
                pass

            if thousand_separator == Format.NONE:
                return ThousandSeparator.NONE
            elif thousand_separator == Format.THOUSAND_SEPARATOR:
                return ThousandSeparator.COMMA

        if thousand_separator is None:
            return ThousandSeparator.NONE

        return thousand_separator