安装
pip install PrettyTable
代码示例
from prettytable import PrettyTable
# 创建表头
table=PrettyTable(["姓名","学号","性别"])
# 插入数据
table.add_row(["小明","01","男"])
table.add_row(["小红","02","女"])
table.add_row(["小黄","03","男"])
# 显示该表
print(table)
"""
+------+------+------+
| 姓名 | 学号 | 性别 |
+------+------+------+
| 小明 | 01 | 男 |
| 小红 | 02 | 女 |
| 小黄 | 03 | 男 |
+------+------+------+
"""
参考:
PrettyTable模块的安装与简单应用(python)