轻量级表格数据,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
  • 打印机(默认打印):允许用户写入 以表格形式打印到文件,或用 作为参数的表格打印输出。每行输出都是 字符串,因此请确保您的函数考虑到这一点。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java OpenShift的齿轮特性   java如何在Liferay站点的每个页面上放置公司地址和电话?   java确定整数数组中是否存在一个子集,在两个条件下求和到给定的目标值   序列化为什么java中的serialVersionUID必须是静态的、最终的、长类型的?   java响应返回null   java注入接口实现Quarkus   java我不明白为什么第二次排序的运行时间比第一次慢?   (Java)显示图像的最佳方式?   java Android应用程序因添加布局而崩溃   java如何在运行时获取泛型变量的类   java Selenium web驱动程序:无效的选择器:*:WebKitFullScreenSentor   Spring中的java注入值始终为空   Eclipse中带有TestNG插件的@BeforeSuite和@AfterSuite的java问题   使用trycatch块、filewriter和printwriter在java中创建自定义类   如何在Java 安卓上绘制相交的两条线