use rich module to create two colums in prompt

1.1k views Asked by At

I'm making a small program that pick random people in a list (a proget for school). The code works fine:

import numpy as np

people = ["0 = Baiesi", "1 = Balducci", "2 = Bulgarelli", "3 = Caffaggi", "4 = Caprara", "5 = Dodi", "6 = Fattore", "7 = Felici", '8 = Marcolin', '9 = Mascagni', '10 = Moretti', '11 = Moschini','12 = Patelli','13 = Sandu','14 = Spinelli','15 = Stevens','16 = Zani']

print(*people, sep = "\n")

n = int(input('Number of people to pick: '))

numbers = [i for i in list(range(len(people)))]
extracted = np.random.choice(numbers, size=n, replace=False)
 
print(extracted)

However I want it to have a specific layout, but I have no idea how to do it. I have done some research online but I didn't find anything that was suited for this case.

This is the current output:

my output

This is the output I am looking for:

output i want

Basically I want that firstly the left "colum" with the names Is printed, than the right "colum" with the user guided part is printed near the names. I Hope I explained myself well. I was thinking of using rich module's tables, the problem Is that this tables are printed "row by row" and not "colum by colum" (hope u understand) which is what I want.

Has someone any idea on how it could be done?

1

There are 1 answers

1
Christopher Emmanuel On
from rich.console import Console
from rich.table import Table


table = Table(title="Todo List")


table.add_column("S. No.",
style="cyan", no_wrap=True)
table.add_column("Task", 
style="magenta")
table.add_column("Status", 
justify="right", style="green")



table.add_row("1", "Buy Milk", "✅")
table.add_row("2", "Buy Bread", "✅")
table.add_row("3", "Buy Jam", "❌")

Run this program and make your modifications by following the examples...