1. pip3 install prettytable
    1. from prettytable import PrettyTable
    2. from prettytable import from_json, from_csv
    3. from logzero import logger
    4. # 表头
    5. tb = PrettyTable()
    6. tb.field_names = ["姓名", "年龄", "出处"]
    7. # 添加行
    8. tb.add_row(["zaygee", 26, "shenzhen"])
    9. tb.add_row(["zaygdddddee2", 3, "shenzhen1"])
    10. tb.add_row(["zayg23434ee3", 24, "shenzhen"])
    11. tb.add_row(["zay", 45, "shenzhen2"])
    12. # 添加多行,参数为list
    13. list_str = [("add_row2", 26, "shenzhen"), ("add_row3", 77, "shenzhen")]
    14. tb.add_rows(list_str)
    15. # 添加列
    16. # tb.add_column("性别", ["女"] * 4)
    17. # 按某个字段倒叙排序输出
    18. print(tb.get_string(sortby="年龄", reversesort=True))
    19. """
    20. +--------------+------+-----------+
    21. | 姓名 | 年龄 | 出处 |
    22. +--------------+------+-----------+
    23. | add_row3 | 77 | shenzhen |
    24. | zay | 45 | shenzhen2 |
    25. | zaygee | 26 | shenzhen |
    26. | add_row2 | 26 | shenzhen |
    27. | zayg23434ee3 | 24 | shenzhen |
    28. | zaygdddddee2 | 3 | shenzhen1 |
    29. +--------------+------+-----------+
    30. """