我正在使用prettytable来生成表。但是当feild的名字太长时,它就不会换线路了。示例代码如下所示:
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())结果是:
+-------------+-------------+-------------+-------------+
| 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 |
+-------------+-------------+-------------+-------------+字段名不完整,而单元格数据已完成。如何使字段名自动切换线?谢谢!
发布于 2022-11-13 18:47:38
现在看过了,你可能已经解决了。我把它张贴在这里为任何其他人寻找相同的答案。添加到表后面
tab = PrettyTable()
tab.header = False你应该这样解决它。再见
https://stackoverflow.com/questions/71432653
复制相似问题