summaryrefslogtreecommitdiffstats
path: root/example3.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-16 09:09:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-16 09:09:35 +0000
commit0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7 (patch)
treea0b651b55ea02e3b00bbc5eedba566fdd6bd7c08 /example3.py
parentInitial commit. (diff)
downloadterminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.tar.xz
terminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.zip
Adding upstream version 3.1.0.upstream/3.1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'example3.py')
-rwxr-xr-xexample3.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/example3.py b/example3.py
new file mode 100755
index 0000000..bec5500
--- /dev/null
+++ b/example3.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+"""Simple example usage of terminaltables and column_max_width().
+
+Just prints sample text and exits.
+"""
+
+from __future__ import print_function
+
+from textwrap import wrap
+
+from terminaltables 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()