• [python2] python 打印表格 prettytable


    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.2
    Release     : 3.el7
    Size        : 37 k
    Repo        : base/7/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) + " ")
    ... ...

    输出:

    [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     |
    +-----------------+---------------+--------------+----------+-----------+---------------+--------------+----------+-----------+
  • 相关阅读:
    【Objective-C学习笔记】变量和基本的数据类型
    数据文件实时同步(rsync + sersync2)
    入园自述
    软件工程人才的社会需求现状与发展趋势分析
    ERP-安心卡功能
    银盒宝成APP下载地址
    关于新商家后台添加商品后,一体机上不显示分类问题解决流程
    各类型商户微信认证方法
    网商微信实名认证FAQ
    扫码下单支持同桌单人点餐FAQ
  • 原文地址:https://www.cnblogs.com/hugetong/p/9332251.html
Copyright © 2020-2023  润新知