Basic Usage

Basic Usage#

import tablate as tb

table_columns = [
    {
        "key": "col_one",
        "string": "Col One",
        "width": "50%"
    },
    {
        "key": "col_two",
        "string": "Col One",
    },
    {
        "key": "col_three",
        "string": "Col One",
    }
]

table_rows = [
    {
        "col_one": "Column One, Row One",
        "col_two": "Column Two, Row One",
        "col_three": "Column Three, Row One"
    },
    {
        "col_one": "Column One, Row Two",
        "col_two": "Column Two, Row Two",
        "col_three": "Column Three, Row Two"
    },
    {
        "col_one": "Column One, Row Three",
        "col_two": "Column Two, Row Three",
        "col_three": "Column Three, Row Three"
    }
]

tab = tb.Tablate()

tab.add_text_frame("This is a basic example for Tablate usage.")
tab.add_grid_frame(["One", "Two", "Three"])
tab.add_table_frame(columns=table_columns, rows=table_rows)

… will produce …

basic_usage

ASCII output:#

.to_string() and .print() methods

The ASCII output can be generated using the ._to_string() method and printed to the console using the .print() method.

ascii_string = tab.to_string()
tab.print()

.__str__() method

The ASCII output is generated by the .__str__() method.

print(tab)

Note: tab.print(), print(tab.to_string()) and print(tab) all produce the same output.

HTML output:#

.to_html() method

The HTML output can be generated using the .to_html() method.

html_string = tab.to_html()

._repr_html_() method

The HTML output is generated by the ._repr_html_() method. The ._repr_html_() method is useful in an IPython environment to easily generate HTML tables.

basic_usage