0

I want to build a table and print it on the console based on the data from a CSV file and the data may change so I need to update the value in rows when the data in the CSV file changes.

This is the code that I end up with each time the loop executes a new table print on the console but I want to have just "ONE" table and the values in rows update any idea? thanks

csv_file = 'result.csv'
headers = ['Column 1', 'Column 2']
table = PrettyTable(headers)

while True:
    
    table.clear_rows()

    
    with open(csv_file, 'r') as f:
        reader = csv.reader(f)
        next(reader) # to skip the header row
        rows = [row for row in reader] # create a list of rows
        table.add_rows(rows)

    
    print(table)

    
    time.sleep(5) # 5 second delay before each iteration

Output:

Output

Saad
  • 3,340
  • 2
  • 10
  • 32
Poori
  • 31
  • 5
  • Please don't post desired result as image. Use code tag instead. Did you mean to use [Python PrettyTable](https://pypi.org/project/prettytable/) ? If so, you should import it, and create an instance of it. See examples at the site. Tip: You can [clear screen for each output](https://stackoverflow.com/questions/517970/how-to-clear-the-interpreter-console) if desired – MyICQ Mar 28 '23 at 16:11

0 Answers0