Why does beautifultable in python do not fit content to the table?

382 Views Asked by At

just started using beautiful table package, when printing the table the content is printed letter by letter instead of as whole word. when Im running the example code the columns and rows are perfectly fitted to the content. what am I doing wrong? please help

table1 = BeautifulTable()
table1.rows.append([1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10])
table1.rows.append(f)
table1.rows.header = ["VR[V]", "Frequency[kHz]"]
table1.columns.header = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]
print(table1)

table = BeautifulTable()
table.rows.append(["Jacob", 1, "boy"])
table.rows.append(["Isabella", 1, "girl"])
table.rows.header = ["S1", "S2"]
table.columns.header = ["name", "rank", "gender"]
print(table)

unfitted table

fitted table

1

There are 1 best solutions below

0
CryptoFool On

Your problem is that the BeautifulTable's constructor takes a parameter named maxwidth, and that value defaults to 80. To solve your problem, just set that value to something bigger. If you never want your data to wrap in a column, set it to something really big, for example:

table1 = BeautifulTable(maxwidth=4000)

I believe that this will give you the result you're looking for.