File: example3.py

package info (click to toggle)
terminaltables3 4.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,324 kB
  • sloc: python: 2,691; makefile: 91; sh: 11
file content (40 lines) | stat: -rwxr-xr-x 1,165 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python3
"""Simple example usage of terminaltables and column_max_width().

Just prints sample text and exits.
"""


from textwrap import wrap

from terminaltables3 import SingleTable

LONG_STRING = (
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore "
    "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
    "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum "
    "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui "
    "officia deserunt mollit anim id est laborum."
)


def main():
    """Main function."""
    table_data = [
        [
            "Long String",
            "",
        ],  # One row. Two columns. Long string will replace this empty string.
    ]
    table = SingleTable(table_data)

    # Calculate newlines.
    max_width = table.column_max_width(1)
    wrapped_string = "\n".join(wrap(LONG_STRING, max_width))
    table.table_data[0][1] = wrapped_string

    print(table.table)


if __name__ == "__main__":
    main()