tabulate是一个帮助你打印标准化表单的库,使用起来非常便捷,支持的格式较多

如何安装呢?

 

Python3  tabulate 打印表格多种样式,总有一款适合你-Python 技术分享 Java技术分享 Python 爬虫技术_微信公众号:zeropython—昊天博客

 

应用:

直接上代码:

 


# -*- coding: utf-8 -*-
"""
@Time: 2018/1/29
@Author: songhao
@微信公众号: zeropython
@File: table01.py
"""
from tabulate import tabulate
table = [
    ["Sun",696000,1989100000],["Earth",6371,5973.6],["Moon",1737,73.5],["Mars",3390,641.85]
        ]
print("表格样式".center(50,'*'))
print(tabulate(table))
print("表格样式".center(50,'*'))
print(tabulate(table, headers=["Planet","R (km)", "mass (x 10^29 kg)"]))
print("表格样式".center(50,'*'))
print(tabulate([["Name","Age"],["Alice",24],["Bob",19]],headers="firstrow"))
print("表格样式".center(50,'*'))
print(tabulate({"Name": ["Alice", "Bob"],"Age": [24, 19]}, headers="keys"))
headers = ["item", "qty",'dd']
print("表格样式".center(50,'*'))
print(tabulate(table, headers, tablefmt="grid"))
print("表格样式".center(50,'*'))
print(tabulate(table, headers, tablefmt="pipe"))
print("表格样式".center(50,'*'))
print(tabulate(table, headers, tablefmt="orgtbl"))

返回结果:

Python3  tabulate 打印表格多种样式,总有一款适合你-Python 技术分享 Java技术分享 Python 爬虫技术_微信公众号:zeropython—昊天博客
Python3  tabulate 打印表格多种样式,总有一款适合你-Python 技术分享 Java技术分享 Python 爬虫技术_微信公众号:zeropython—昊天博客
HTTPX 基础教程-新乡seo|网站优化,网站建设_微信公众号:zeropython—昊天博客