I am trying to print a table inside a border. As you can see, without the border, the table prints fine, but when I put a border, it just does not print properly. Please help me accomplish this. If there is any other easy way, please suggest.
import tabulate
from textwrap import wrap
import prettytable as pt
apps_iter_data = [
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"},
{"hello1": "hello1_data","hello2": "hello1_data","hello3": "hello1_data","hello4": "hello1_data","hello5": "hello1_data","hello6": "hello1_data"}
]
message_type = "info"
header = apps_iter_data[0].keys()
rows = [x.values() for x in apps_iter_data]
message = tabulate.tabulate(rows, header)
print(message)
width = len(message.splitlines()[1])
t = pt.PrettyTable()
t.field_names = [message_type.upper()]
[t.add_row([message[i:i + width]]) for i in range(0, len(message), width)]
print(t)
hello1 hello2 hello3 hello4 hello5 hello6
----------- ----------- ----------- ----------- ----------- -----------
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data
+------------------------------------------------------------------------------+
| INFO |
+------------------------------------------------------------------------------+
| hello1 hello2 hello3 hello4 hello5 hello6 |
| ---- |
| ------- ----------- ----------- ----------- ----------- ----------- |
| hel |
| lo1_data hello1_data hello1_data hello1_data hello1_data hello1_data |
| he |
| llo1_data hello1_data hello1_data hello1_data hello1_data hello1_data |
| h |
| ello1_data hello1_data hello1_data hello1_data hello1_data hello1_data |
| |
| hello1_data hello1_data hello1_data hello1_data hello1_data hello1_data |
| |
| hello1_data hello1_data hello1_data hello1_data hello1_data hello1_dat |
| a |
| hello1_data hello1_data hello1_data hello1_data hello1_data hello1_da |
| ta |
| hello1_data hello1_data hello1_data hello1_data hello1_data hello1_d |
| ata |
+------------------------------------------------------------------------------+