I'm using prettytable
module for pretty printing. I'd like to know how to save the prettytable instances. I know how to print it to a file but I want to save it somewhere, like pickling, if that's possible. And later, I'd like to access these variables as well. Can anybody help me out?
My pretty table looks like the following:
from prettytable import PrettyTable
field_names = ["S.No", "username", "created_at", "result"]
tab = PrettyTable(field_names)
tab.padding_width = 1
tab.add_row([1, 'foo', '28-10-2016', 'Yes'])
tab.add_row([2, 'bar', '29-10-2016', 'Noo'])
But I'm appending lot more rows to the table sometimes it will be 100.
Ideally, I'd like to save the variable tab
and at a later time access all the rows that I appended to tab
.
How can I achieve this? Also, is it possible to access individual values like tab[1][1]
which will give bar
as output? I tried this but it didn't work. Instead the whole row is printed.