下面介绍一个快速制作ASCII表格库——prettytable,可以方便地制作简单表格。
1 安装prettytable
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple prettytable
结果如下:
2 代码实例
from prettytable import PrettyTable
table = PrettyTable()
table.field_names = ["学号", "姓名", "语文", "数学", "英语", "物理", "化学", "总分", "平均分"]
table.add_row(["20170001", "张三", 85, 92, 78, 88, 90, 513, 64.13])
table.add_row(["20170002", "李四", 75, 80, 85, 90, 78, 508, 63.5])
table.add_row(["20170003", "王五", 90, 95, 92, 88, 85, 550, 68.75])
print(table)
结果如下: