Skip to main content

a library for drawing the table in the terminal

Project description

Printtable是一个可以在terminal上输出数据表样式的python公共库。

下载方式

 pip install printtable

引用printtable

 from printtable import PrintTable

首先我们需要构建表的表头,然后创建表

attributes=[[‘name’,’old’]]

table = PrintTable(attributes)

然后我们有两种方式向表内加入数据

1.append_data:可以通过明确特征来加入一行数据中的一部分数据或者多行数据。

 table.append_data(name=”Jack”,old = “20”)

 table.append_data(name =[“Jack”,”Mary”], old =[“20”,”19”])

2.append_data_list: 可以直接使用list格式的变量向表中加入一行数据。不过要注意数据的顺序要符合创建表时的表头相同。

 table.append_data_list([“Jack”,”20”])

支持加入中文数据,但表头目前只能支持英文。

 table.append_data(name = “小明”,old = “20”)

 table.append_data(name =[“小华”,”大傻”], old =[“20”,”19”])

 table.append_data_list([“二傻子”,”20”])

最后我们可以在terminal直接输出ASCII表。通过line_num参数来控制在每行数据前是否加上行号,1为加入,默认为不加入行号。

table.printTable(1)

table.printTable()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

printtable-1.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

printtable-1.2-py2.7.egg (6.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page