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 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)