1

How could I erase a row table in rich? (Erase the rows or reset all the table)

ex. How could I reset tableTest or erase a row?

from rich.console import Console
from rich.table import Table

tableTest = Table(title="Star Wars Movies")

tableTest.add_column("Released", justify="right", style="cyan", no_wrap=True)
tableTest.add_column("Title", style="magenta")
tableTest.add_column("Box Office", justify="right", style="green")

tableTest.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690")
tableTest.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347")
tableTest.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
tableTest.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")

console = Console()
console.print(tableTest)
vitaliis
  • 4,082
  • 5
  • 18
  • 40
Todeshine
  • 13
  • 4
  • How do you know that there are such methods as `add_column` or `add_row`? By looking in the documentation, right? Did you try looking through the documentation again, to see if there is anything that looks like it might do what you now want? – Karl Knechtel Apr 18 '22 at 13:48
  • Yes i did. This question it's my desperate act. https://rich.readthedocs.io/en/stable/reference/table.html https://rich.readthedocs.io/en/stable/tables.html – Todeshine Apr 18 '22 at 13:52

2 Answers2

1

No, rich does not provide any APIs to Delete/Remove the rows. See this Support for deleting/removing rows/columns from table to understand why no such APIs are added to the Table class.

Abdul Niyas P M
  • 18,035
  • 2
  • 25
  • 46
1

Just reinitialize the table.

def resetTable():
    global tableTest

    tableTest = Table(title="Star Wars Movies")

    tableTest.add_column("Released", justify="right", style="cyan", no_wrap=True)
    tableTest.add_column("Title", style="magenta")
    tableTest.add_column("Box Office", justify="right", style="green")

And call resetTable() whenever you want to reset your table

Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36