PrettyTable is a simple Python library designed to make it quick and easy to represent tabular data in visually appealing ASCII tables. It was inspired by the ASCII tables used in the PostgreSQL shell psql. PrettyTable allows for selection of which columns are to be printed, independent alignment of columns (left or right justified or centred) and printing of “sub-tables” by specifying a row range.
PrettyTable 是用于格式化表单输出的第三方库,官方有提供安装方法,也可以下载指定版本后执行安装命令:
cd "local PrettyTable dir" |
简单用法:
from prettytable import PrettyTable |
运行结果:
+-----------+------+------------+-----------------+ |
不用自己对齐文本的体验简直爽歪歪,更多API参见官方文档。