Dynamic Random Table Generation with Rich Library

  • Share this:

Code introduction


This function uses the Rich library to generate a table containing names, ages, and cities, and dynamically generates table content based on input parameters.


Technology Stack : Rich library, Python programming language

Code Type : The type of code

Code Difficulty :


                
                    
def generate_random_table(arg1, arg2, arg3):
    from rich.console import Console
    from rich.table import Table

    console = Console()
    table = Table(show_header=True, header_style="bold magenta")
    table.add_column("Name", justify="left", style="dim")
    table.add_column("Age", style="green")
    table.add_column("City", style="yellow")

    for i in range(arg1):
        table.add_row(f"Person {i+1}", f"{arg2}", f"{arg3}")

    console.print(table)