You can download this code by clicking the button below.
This code is now available for download.
This function uses the Table class from the Rich library to create a table and the Console class to print the table. The function accepts a list of data, where each element is a tuple containing the name, age, and country information.
Technology Stack : Rich
Code Type : Table display in the Rich library
Code Difficulty : Intermediate
def rich_table_example(data):
from rich.table import Table
from rich.console import Console
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Name", justify="right")
table.add_column("Age", justify="center")
table.add_column("Country", justify="left")
console = Console()
for row in data:
table.add_row(row[0], row[1], row[2])
console.print(table)