My script needs to print a table while it is crunching some numbers. Its total run time is several hours, and I need it to add more and more rows to the printed table while it is running. I am trying to use PrettyTable, but I am open to other suggestions how else it can be accomplished. Here is an example of what I am trying to do:
from prettytable import PrettyTable
t = PrettyTable(['Name', 'Age'])
t.add_row(['Alice', 24])
print t
#do some work
t.add_row(['Bob', 19])
print t
The outcome that I get is this:
+-------+-----+
| Name | Age |
+-------+-----+
| Alice | 24 |
+-------+-----+
+-------+-----+
| Name | Age |
+-------+-----+
| Alice | 24 |
| Bob | 19 |
+-------+-----+
Is there a way not to print the entire table every time I add a row but print just a new row underneath of what has already been printed? I am trying to get somethig like this:
+-------+-----+
| Name | Age |
+-------+-----+
| Alice | 24 |
+-------+-----+
| Bob | 19 |
+-------+-----+
Left alignment for the first column would be a nice bonus.