rich

Utilities

終端樣式

概述 rich

Rich 是一個用於將富文本寫入終端機的 Python 函式庫。它支援 Markdown 渲染、語法突出顯示、表格、進度條、漂亮列印的回溯以及各種其他格式選項 - 所有這些都具有簡單、富有表現力的 API。

在PyRun的終端機中,Rich 的樣式以格式化輸出的形式出現,使其成為建立精美的 CLI 輸出的出色工具。無論您是要建立資料報告腳本還是只是想要更好的列印報表,Rich 都可以透過 micropip 開箱即用,無需安裝。

程式碼和執行輸出

使用豐富的庫設計面板和表格。

Rich Terminal Tables在編輯器中執行
from rich.console import Console
from rich.table import Table
from rich.panel import Panel

console = Console()

console.print(Panel.fit("[bold green]Welcome to PyRun[/bold green]", border_style="green"))

table = Table(title="Top Programming Languages")
table.add_column("Rank", justify="center", style="cyan", no_wrap=True)
table.add_column("Language", style="magenta")
table.add_column("Type", style="green")
table.add_column("Popular For", style="yellow")

table.add_row("1", "Python",     "Dynamic", "Data Science, AI")
table.add_row("2", "JavaScript", "Dynamic", "Web, Node")
table.add_row("3", "TypeScript", "Static",  "Large-scale Web")
table.add_row("4", "Rust",       "Static",  "Systems, WASM")

console.print(table)

相關套餐

推薦的 Python 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。