How to use the pytablewriter.RstSimpleTableWriter 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_writer_factory.py View on Github external
            ["rst_simple_table", ptw.RstSimpleTableWriter],
            ["rst_csv_table", ptw.RstCsvTableWriter],
            ["space_aligned", ptw.SpaceAlignedTableWriter],
            ["SPACE_ALIGNED", ptw.SpaceAlignedTableWriter],
            ["sqlite", ptw.SqliteTableWriter],
            ["SQLite", ptw.SqliteTableWriter],
            ["tsv", ptw.TsvTableWriter],
            ["TSV", ptw.TsvTableWriter],
            ["toml", ptw.TomlTableWriter],
            ["TOML", ptw.TomlTableWriter],
            ["unicode", ptw.UnicodeTableWriter],
            ["Unicode", ptw.UnicodeTableWriter],
        ],
    )
    def test_normal(self, format_name, expected):
        writer = ptw.TableWriterFactory.create_from_format_name(format_name)
github thombashi / pytablewriter / test / writer / text / test_rst_simple_writer.py View on Github external
"""\
            .. table:: table name

                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
                i   f     c     if   ifc  bool     inf     nan  mix_num             time           
                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
                1  1.10  aa     1.0    1  True   Infinity  NaN         1  2017-01-01T00:00:00      
                2  2.20  bbb    2.2  2.2  False  Infinity  NaN  Infinity  2017-01-02 03:04:05+09:00
                3  3.33  cccc  -3.0  ccc  True   Infinity  NaN       NaN  2017-01-01T00:00:00      
                =  ====  ====  ====  ===  =====  ========  ===  ========  =========================
            """
        ),
    ),
]

table_writer_class = pytablewriter.RstSimpleTableWriter


class Test_RstSimpleTableWriter_write_new_line(object):
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()

        out, _err = capsys.readouterr()
        assert out == "\n"


class Test_RstSimpleTableWriter_write_table(object):
    @pytest.mark.parametrize(
        ["table", "indent", "header", "value", "expected"],
        [
            [data.table, data.indent, data.header, data.value, data.expected]
github thombashi / pytablewriter / examples / py / multi_byte_table.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi 
"""

import pytablewriter


writer = pytablewriter.RstSimpleTableWriter()
writer.table_name = "็”Ÿๆˆใซ้–ขใ™ใ‚‹ใƒ‘ใ‚ฟใƒผใƒณ"
writer.headers = ["ใƒ‘ใ‚ฟใƒผใƒณๅ", "ๆฆ‚่ฆ", "GoF", "Code Complete[1]"]
writer.value_matrix = [
    ["Abstract Factory", "้–ข้€ฃใ™ใ‚‹ไธ€้€ฃใฎใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’็Šถๆณใซๅฟœใ˜ใฆใ€้ฉๅˆ‡ใซ็”Ÿๆˆใ™ใ‚‹ๆ–นๆณ•ใ‚’ๆไพ›ใ™ใ‚‹ใ€‚", "Yes", "Yes"],
    ["Builder", "่ค‡ๅˆๅŒ–ใ•ใ‚ŒใŸใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใฎ็”Ÿๆˆ้Ž็จ‹ใ‚’้š ่”ฝใ™ใ‚‹ใ€‚", "Yes", "No"],
    ["Factory Method", "ๅฎŸ้š›ใซ็”Ÿๆˆใ•ใ‚Œใ‚‹ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใซไพๅญ˜ใ—ใชใ„ใ€ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใฎ็”Ÿๆˆๆ–นๆณ•ใ‚’ๆไพ›ใ™ใ‚‹ใ€‚", "Yes", "Yes"],
    ["Prototype", "ๅŒๆง˜ใฎใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’็”Ÿๆˆใ™ใ‚‹ใŸใ‚ใซใ€ๅŽŸๅž‹ใฎใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’่ค‡่ฃฝใ™ใ‚‹ใ€‚", "Yes", "No"],
    ["Singleton", "ใ‚ใ‚‹ใ‚ฏใƒฉใ‚นใซใคใ„ใฆใ€ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใŒๅ˜ไธ€ใงใ‚ใ‚‹ใ“ใจใ‚’ไฟ่จผใ™ใ‚‹ใ€‚", "Yes", "Yes"],
]
writer.dump("multibyte_table_output.txt")
github thombashi / typepy / docs / make_result_matrix.py View on Github external
def __init__(self):
        self.typeclass = None
        self.strict_level = None
        self.headers = None
        self.value_list = None

        self.__table_writer = ptw.RstSimpleTableWriter()
        self.__table_writer._dp_extractor.type_value_map = {
            NullString(None).typecode: '``""``',
            NoneType(None).typecode: "``None``",
            Infinity(None).typecode: '``Decimal("inf")``',
            Nan(None).typecode: '``Decimal("nan")``',
        }
        self.__table_writer.value_map = {
            True: "``True``",
            False: "``False``",
            '``"127.0.0.1"``': '``ip_address("127.0.0.1")``',
        }
github hugovk / pypistats / src / pypistats / __init__.py View on Github external
def _tabulate(data, format="markdown"):
    """Return data in specified format"""

    format_writers = {
        "markdown": MarkdownTableWriter,
        "rst": RstSimpleTableWriter,
        "html": HtmlTableWriter,
    }

    writer = format_writers[format]()
    if format != "html":
        writer.margin = 1

    if isinstance(data, dict):
        header_list = list(data.keys())
        writer.value_matrix = [data]
    else:  # isinstance(data, list):
        header_list = sorted(set().union(*(d.keys() for d in data)))
        writer.value_matrix = data

    # Move downloads last
    header_list.append("downloads")