import csv class Table: columnNames = [] rows = [] def __init__(self, columns): self.columnNames = columns def addRow(self, values): self.rows.append(values) def getLastRow(self): if len(self.rows) > 0: return self.rows[len(self.rows)-1] else: return [0] * len(self.columnNames) def getLastValue(self, column): col = self.columnNames.index(column) return self.getLastRow(col) def saveAsCsv(self, filename): with open(filename,"w+", newline='') as my_csv: csvWriter = csv.writer(my_csv,delimiter=',') csvWriter.writerow(self.columnNames) csvWriter.writerows(self.rows) if __name__ == "__main__": t = Table(["time", "col1", "col2"]) t.addRow([time.time(), 1, 2]) t.addRow([time.time(), 3, 4]) print(len(t.rows)) print(t.getLastRow())