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: