轻量级表格数据,python打印模块。
tabular-print的Python项目详细描述
表格打印
tabular print打印缩放列宽以适应数据的表。 使用sqlite3 python模块编写为mesh,特别是 cursor.description(列表只包含列标签),以及 cursor.fetchall()。值列表中的每一行都被视为 表数据,列表中元素的顺序与 列标签。如果数据的格式为 表示数据列的每一行。
示例
我的一个副业项目(https://github.com/mkitzan/terminus)的修订示例:
*--------------------------------------*---------------*----------------*-----*------*--------* |Title |Author |Genre |Year |Pages |Type | *--------------------------------------*---------------*----------------*-----*------*--------* |Ellison Wonderland |Harlan Ellison |science fiction |1962 |191 |stories | |Dangerous Visions |Harlan Ellison |science fiction |1967 |598 |stories | |Love Ain't Nothing but Sex Misspelled |Harlan Ellison |science fiction |1968 |380 |stories | |Again, Dangerous Visions vol.1 |Harlan Ellison |science fiction |1972 |450 |stories | |Again, Dangerous Visions vol.2 |Harlan Ellison |science fiction |1972 |449 |stories | |Approaching Oblivion |Harlan Ellison |science fiction |1974 |164 |stories | |Deathbird Stories |Harlan Ellison |science fiction |1975 |347 |stories | |Stalking the Nightmare |Harlan Ellison |science fiction |1982 |301 |stories | |Angry Candy |Harlan Ellison |science fiction |1988 |324 |stories | |Slippage |Harlan Ellison |science fiction |1997 |359 |stories | *--------------------------------------*---------------*----------------*-----*------*--------*
用法
首先从表格打印中导入函数“table”
from tabularprint import table
对于标准表使用
table(col_labels, values)
对于扩展表,使用预期的参数和任何组合 五个非标准参数中的
table(col_labels, values, header="Look at this table", transpose=True, edge="#", padding=2, printer=lambda row: outfile.write(row + "\n"))
非标准参数
- header(默认为none):将在 桌子。
- transpose(默认为false):如果 转置=真。如果值中的行对应于 表而不是预期值行对应于表 行(sqlite3 fetchall调用的格式)
- 边(默认“*”):当水平线(“-”)与 垂直线(“”)在表中,放置一个边缘字符。由 默认情况下使用星号,但是在 表被调用时,可以扩展此字符的内容。
- padding(默认值1):buffer确定空白的数量 在列中最长值的结尾和该列的 右垂直分隔线。示例:缓冲区示例=1
- 打印机(默认打印):允许用户写入 以表格形式打印到文件,或用 作为参数的表格打印输出。每行输出都是 字符串,因此请确保您的函数考虑到这一点。