標準出力したい(rich

1from rich import print
2print("Hello, [bold magenta]Rich[/bold magenta]!")

richは、Pythonの標準出力を装飾するためのライブラリです。

rich.print関数に置き換えるだけで、テキストの色やスタイルを指定して、見やすく、わかりやすい出力を実現できます。

コンソール出力したい(rich.console.Console

1import sys
2from rich.console import Console
3stdout = Console(file=sys.stdout)
4stderr = Console(file=sys.stderr)
5
6stdout.print("This is a message to standard output.", style="green")
7stderr.print("This is a message to standard error.", style="red")

rich.console.Consoleを使って、標準出力や標準エラーに装飾されたテキストを出力できます。

Consoleオブジェクトを作成するときに、file引数で出力先を変更できます。 システムの標準出力(sys.stdout)や標準エラー出力(sys.stderr)を指定するのが最近の個人的なお気に入りです。