You can download this code by clicking the button below.
This code is now available for download.
This code defines a function that uses the Rich library to create a table and fills it according to the provided number of columns and rows. The function first creates a console object and a table object, then adds columns and rows to the table according to the given number of columns and rows, and finally prints the table to the console.
Technology Stack : Rich, Console, Table, Text
Code Type : The type of code
Code Difficulty :
import random
from rich.console import Console
from rich.table import Table
from rich.text import Text
from rich.console import Console
def random_table_generator(columns, rows):
console = Console()
table = Table(show_header=True, header_style="bold magenta", padding=2)
table.add_column("Column 1", style="dim", justify="left")
table.add_column("Column 2", style="dim", justify="left")
table.add_column("Column 3", style="dim", justify="left")
for i in range(rows):
row = [f"Row {i+1}", f"Value {i+1}", f"Description {i+1}"]
table.add_row(*row)
console.print(table)