zoukankan      html  css  js  c++  java
  • python 用 prettytable 输出漂亮的表格

    原文链接:https://linuxops.org/blog/python/prettytable.html

    #!/usr/bin/python
    #**coding:utf-8**
    import sys
    from prettytable import PrettyTable
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    table = PrettyTable(['编号','云编号','名称','IP地址'])
    table.add_row(['1','server01','服务器01','172.16.0.1'])
    table.add_row(['2','server02','服务器02','172.16.0.2'])
    table.add_row(['3','server03','服务器03','172.16.0.3'])
    table.add_row(['4','server04','服务器04','172.16.0.4'])
    table.add_row(['5','server05','服务器05','172.16.0.5'])
    table.add_row(['6','server06','服务器06','172.16.0.6'])
    table.add_row(['7','server07','服务器07','172.16.0.7'])
    table.add_row(['8','server08','服务器08','172.16.0.8'])
    table.add_row(['9','server09','服务器09','172.16.0.9'])
    print(table)

    运行结果:

    +------+----------+----------+------------+
    | 编号 |  云编号  |   名称   |   IP地址   |
    +------+----------+----------+------------+
    |  1   | server01 | 服务器01 | 172.16.0.1 |
    |  2   | server02 | 服务器02 | 172.16.0.2 |
    |  3   | server03 | 服务器03 | 172.16.0.3 |
    |  4   | server04 | 服务器04 | 172.16.0.4 |
    |  5   | server05 | 服务器05 | 172.16.0.5 |
    |  6   | server06 | 服务器06 | 172.16.0.6 |
    |  7   | server07 | 服务器07 | 172.16.0.7 |
    |  8   | server08 | 服务器08 | 172.16.0.8 |
    |  9   | server09 | 服务器09 | 172.16.0.9 |
    +------+----------+----------+------------+
  • 相关阅读:
    Codeforces
    BZOJ
    BZOJ
    HDU
    Codeforces
    codeforces
    HDU-5441 Travel 离线-并查集
    codefoeces-1000E We Need More Bosses(tarjan+最长链)
    牛客网暑期ACM多校训练营(第五场)H-subseq 树状数组
    HDU-3533 Escape (BFS
  • 原文地址:https://www.cnblogs.com/wangjq19920210/p/12426221.html
Copyright © 2011-2022 走看看