python打表格_[python2] python 打印表格 prettytable

rpm包:

[root@D129 cli]# yum info python-prettytable

Loaded plugins: fastestmirror

Loading mirror speedsfromcached hostfile*epel: mirrors.huaweicloud.com*extras: mirrors.cn99.com*updates: mirrors.cn99.com

Available Packages

Name : python-prettytable

Arch : noarch

Version :0.7.2Release :3.el7

Size :37k

Repo :base/7/x86_64

Summary : Python library to display tabular dataintables

URL : http://pypi.python.org/pypi/PrettyTable

License : BSD

Description : PrettyTableisa simple Python library designed to make it quick and easy to

: represent tabular datainvisually appealing ASCII tables. It was inspired by

: the ASCII tables usedin 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.

[root@D129 cli]#

官网:

https://code.google.com/archive/p/prettytable/

文档:

https://code.google.com/archive/p/prettytable/wikis/Tutorial.wiki

小例子:

from prettytable importPrettyTable

... ...

x= PrettyTable(["port", "rx_pps", "rx_bps", "rx_drops", "rx_errors", "tx_pps", "tx_bps", "tx_drops", "tx_errors"])

x.align["port"] = "l"... ...

for i inrange(length):

x.add_row([new_item.port, rpps, rbps, rx_drop, rx_errs, tpps, tbps, tx_drop, tx_errs])

sys.stderr.write(str(x)+ "\n")

... ...

输出:

[root@A04-R08-I244-12-9283C72 tong]#./ovs-stat.py 1>/dev/null

+-----------------+--------+--------+----------+-----------+--------+--------+----------+-----------+

| port | rx_pps | rx_bps | rx_drops | rx_errors | tx_pps | tx_bps | tx_drops | tx_errors |

+-----------------+--------+--------+----------+-----------+--------+--------+----------+-----------+

| dpdk0 | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

| port-uzwlar0rxo | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

| vx10.0.57.13 | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

| vx10.0.54.235 | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

+-----------------+--------+--------+----------+-----------+--------+--------+----------+-----------+

+-----------------+---------------+--------------+----------+-----------+---------------+--------------+----------+-----------+

| port | rx_pps | rx_bps | rx_drops | rx_errors | tx_pps | tx_bps | tx_drops | tx_errors |

+-----------------+---------------+--------------+----------+-----------+---------------+--------------+----------+-----------+

| dpdk0 | 1.54353919126 | 180.20820058 | 0 | 0 | 1.54353919126 | 183.68116376 | 0 | 0 |

| port-uzwlar0rxo | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

| vx10.0.57.13 | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

| vx10.0.54.235 | 0.0 | 0.0 | 0 | 0 | 0.0 | 0.0 | 0 | 0 |

+-----------------+---------------+--------------+----------+-----------+---------------+--------------+----------+-----------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值