I am using prettytable to generate tables. But when the feild name is too long, it won't switch lines. The example code is like below:
import prettytable
x = prettytable.PrettyTable()
x.max_table_width = 50
x.hrules = prettytable.ALL
x.vrules = prettytable.ALL
x.add_column("Field 1 is too long", ['Cell data also too long', 1])
x.add_column("Field 2 is too long", ['Cell data also too long', 2])
x.add_column("Field 3 is too long", ['Cell data also too long', 3])
x.add_column("Field 4 is too long", ['Cell data also too long', 4])
print(x.get_string())
The result is:
+-------------+-------------+-------------+-------------+
| Field 1 is | Field 2 is | Field 3 is | Field 4 is |
+-------------+-------------+-------------+-------------+
| Cell data | Cell data | Cell data | Cell data |
| also too | also too | also too | also too |
| long | long | long | long |
+-------------+-------------+-------------+-------------+
| 1 | 2 | 3 | 4 |
+-------------+-------------+-------------+-------------+
The field name is incomplete, while the cell data is complete. How to make the field name auto switch lines? Thanks!