rpm包:

[root@D129 cli]# yum info python-prettytable
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.huaweicloud.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Available Packages
Name : python-prettytable
Arch : noarch
Version : 0.7.
Release : .el7
Size : k
Repo : base//x86_64
Summary : Python library to display tabular data in tables
URL : http://pypi.python.org/pypi/PrettyTable
License : BSD
Description : 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. [root@D129 cli]#

官网:

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

文档:

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

小例子:

from prettytable import PrettyTable

... ...

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 in range(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 |
+-----------------+---------------+--------------+----------+-----------+---------------+--------------+----------+-----------+

[python2] python 打印表格 prettytable的更多相关文章

  1. Python打印表格

    使用Python在终端打印表格 import prettytable table = PrettyTable(['Title1', 'Title2', 'Title3']) table.add_row ...

  2. Python模块之"prettytable"

    Python模块之"prettytable" 摘要: Python通过prettytable模块可以将输出内容如表格方式整齐的输出.(对于用Python操作数据库会经常用到) 1. ...

  3. Python打印格式化与字符串

    关于Python打印格式化与字符串,比较全面的总结,希望对大家有帮助~ # -*- coding: cp936 -*- ''' 打印格式 ''' print "a" print & ...

  4. python打印表格式数据,留出正确的空格和段落星号或注释

    python打印表格式数据,留出正确的空格,格式化打出 代码如下: def printPicnic(itemsDict,leftWidth,rightWidth): print('PICNIC ITE ...

  5. Lodop打印表格带页头页尾 自动分页每页显示头尾

    Lodop中有两种专门给超文本表格的方式,ADD_PRINT_TABLE和ADD_PRINT_TBURL,该方式只能用于单个表格,表格外的内容不显示,是专门用于打印html超文本表格的.使用这两个语句 ...

  6. Lodop打印表格带页头页尾 高度是否包含页头页尾

    通过设置TableHeightScope,可以实现对ADD_PRINT_TABLE,表格带页头页尾,查看本博客另一篇博文:Lodop打印表格带页头页尾 自动分页每页显示头尾 超文本超过打印项高度,会自 ...

  7. python 打印 emoji

    python 打印 emoji 如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/10486506.html 一.Unicode字符集: ...

  8. python打印列表的下标和值的例子:

    python打印列表的下标和值的例子: In [1]: list01=[1,4,5] In [10]: def funct01(ll):   ....:     for index,value in ...

  9. MVC打印表格,把表格内容放到部分视图打印

    假设在一个页面上有众多内容,而我们只想把该页面上的表格内容打印出来,window.print()方法会把整个页面的内容打印出来,如何做到只打印表格内容呢? 既然window.print()只会打印整页 ...

随机推荐

  1. Socket网络编程--聊天程序(4)

    上一小节讲到可以实现多客户端与服务器进行通讯,对于每一个客户端的连接请求,服务器都要分配一个进程进行处理.对于多用户连接时,服务器会受不了的,而且还很消耗资源.据说有个select函数可以用,好像还很 ...

  2. DBNull与Null的区别

    Null是.net中无效的对象引用. DBNull是一个类.DBNull.Value是它唯一的实例.它指数据库中数据为空(<NULL>)时,在.net中的值. null表示一个对象的指向无 ...

  3. git push origin master和git push有什么区别?

    1.master是主分支,还可以建一些其他的分支用于开发.2.git push origin master的意思就是上传本地当前分支代码到master分支.git push是上传本地所有分支代码到远程 ...

  4. 安装 Xshell 5/6 时出现.dll以及0xc000007错误的解决

    安装 Xshell 5/6 时出现.dll以及0xc000007错误的解决 问题:缺少 mfc110.dll或者是其他.dll文件以及应用程序运行错误,如下所示. 方法: 一种是网上直接下载.(缺少. ...

  5. Android studio 怎么使用单元测试(不需要device)

    关于单元测试的使用,写代码过程中有时候需要检测下代码逻辑的可行性与正确性,又不想通过设备运行,那么就可以通过单元测试跑下代码~ 1.首先建立一个Android studio的Android项目: 2. ...

  6. Python encode() 方法(转)

    转自:http://www.cnblogs.com/wushuaishuai/p/7686290.html 描述 encode() 方法以指定的编码格式编码字符串,默认编码为 'utf-8'. 对应的 ...

  7. SFTP编辑linux文件 ——mac sublime text2 sftp

    llinux上编辑文件总是个头疼的事儿.mac上没有nodepad++和editplus,他们都有各自支持的sftp插件,editplus比较好 自然就带了,而notepad++需要另行安装. 下面介 ...

  8. [IR] XPath for Search Query

    XPath 1.0 XPath Containment Distributed Query Evaluation RE and DFA XPath 1.0 -- 在XML中的使用 XPath 语法: ...

  9. 由n个元素组成的数组,n-2个数出现了偶数次,两个数出现了奇数次,且这两个数不相等,如何用O(1)的空间复杂度,找出这两个数

    思路分析: 方法一:涉及到两个数,就要用到异或定理了:若a^b=x,则a=b^x,b=x^a.对于这道题,假设这两个数分别为a.b,将数组中所有元素异或之后结果为x,因为a!=b,所以x=a^b,且x ...

  10. c __cplusplus详解

    Code:#ifdef __cplusplusextern "C" { #endif ... #ifdef __cplusplus} #endif 解释:1.c++中定义了__cp ...