How to use the pytablewriter.RstGridTableWriter 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
                ["valid_ext.rst", "valid_ext.RST", ".rst", "RST"], [ptw.RstGridTableWriter]
            )
        )
        + list(
            itertools.product(
                ["valid_ext.sqlite", "valid_ext.sqlite3", ".sqlite", "SQLITE"],
                [ptw.SqliteTableWriter],
            )
        )
        + list(
            itertools.product(
                ["valid_ext.tex", "valid_ext.TEX", ".tex", "TEX"], [ptw.LatexMatrixWriter]
            )
        )
        + list(
            itertools.product(
                ["valid_ext.tsv", "valid_ext.TSV", ".tsv", "TSV"], [ptw.TsvTableWriter]
github thombashi / pytablewriter / test / writer / text / test_rst_grid_writer.py View on Github external
value=[["v1\nv1", "v2\n\nv2", "v3\r\nv3"]],
        expected=dedent(
            """\
            .. table:: line breaks will be converted to a white space

                +-----+-----+-----+
                | a b | c d | e f |
                +=====+=====+=====+
                |v1 v1|v2 v2|v3 v3|
                +-----+-----+-----+
            """
        ),
    ),
]

table_writer_class = pytablewriter.RstGridTableWriter


class Test_RstGridTableWriter_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_RstGridTableWriter_write_table(object):
    @pytest.mark.parametrize(
        ["table", "indent", "header", "value", "expected"],
        [
github beeware / toga / contrib / build_compat_tables.py View on Github external
for c, v in _maps.items():
        label = ':mod:`{0}`'.format(c[1]) if c[1] is not None else c[0]
        i = list([label])
        for platform in _platforms:
            if platform in v:
                i.append('|yes|')
            else:
                i.append('|no|')
        writer.value_matrix.append(i)
    
    writer.write_table()
    doc.write(_footer)

for component, value in _maps.items():
    with open('../docs/reference/supported_platforms/{0}.rst'.format(component[0]), 'w+') as doc:
        writer = pytablewriter.RstGridTableWriter()
        writer.stream = doc
        # writer.table_name = "Supported platforms"
        writer.header_list = ["Component"] + _platforms
        writer.value_matrix = []
        i = list([component[0]])
        for platform in _platforms:
            if platform in value:
                i.append('|yes|')
            else:
                i.append('|no|')
        writer.value_matrix.append(i)
        writer.write_table()
        
        doc.write(_footer)

print("Done.")
github Lichee-Pi / Lichee-Zero-Doc-zh-CN / py_tool / table.py View on Github external
import sys

# ่ฆๅ†™ๅ…ฅ็š„ๆ–‡ไปถๅ
filepath = "table.rst"

# ---python2 ๆœ‰ๆ•ˆ--- #
reload(sys)  # ้‡ๆ–ฐ่ฝฝๅ…ฅsys.setdefaultencoding ๆ–นๆณ•
sys.setdefaultencoding('utf-8')
# End of reload #

file1 = open(filepath, 'w+')  # ๆ‰“ๅผ€ๆ–‡ไปถ
file1.truncate()  # ๆธ…็ฉบๆ–‡ไปถๅ†…ๅฎน
file1.close()

# set as rst writer
writer = pytablewriter.RstGridTableWriter()
# change the stream to a string buffer to get the output as a string
writer.stream = six.StringIO()

writer.header_list = ['SPIๅฑ', 'zero']

writer.value_matrix = [
    ['3v3', '3v3'],
    ['GND', 'GND'],
    ['DC', 'PWM1'],
    ['RST', '3v3'],
    ['CS', 'CS'],
    ['CLK', 'CLK'],
    ['MISO', 'MISO'],
    ['MOSI', 'MOSI'],
]
github thombashi / pytablewriter / examples / py / from_csv_text.py View on Github external
# encoding: utf-8

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

import pytablewriter


csv_data = u""""i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09: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-01 00:00:00+09:00"
"""

writer = pytablewriter.RstGridTableWriter()
writer.from_csv(csv_data)
writer.write_table()
github algoo / preview-generator / build_supported_mimetypes_table_rst.py View on Github external
import pytablewriter

from preview_generator.manager import PreviewManager

pm = PreviewManager("/tmp/cache")

writer = pytablewriter.RstGridTableWriter()
writer.table_name = "Supported mimetypes table"
writer.headers = ["MIME type", "Extension"]
matrix = []


for builder in pm._factory.builders_classes:
    try:
        mimetypes = builder.get_supported_mimetypes()
        if not mimetypes:
            continue
        matrix.append(["**{}**".format(builder.get_label())])
        for mimetype in mimetypes:
            extensions = ", ".join(pm.get_file_extensions(mimetype)) or " - "
            matrix.append([mimetype, extensions])
    except NotImplementedError:
        pass  # probably abstract class, so ignore it