I have the following prettytable: import operator
from prettytable import PrettyTable
table = PrettyTable(["Name","Month", "Grade"])
table.title="title test"
table.add_row(["Joe","Jan", 90])
table.add_row(["Sally", "Feb", 100])
table.add_row(["Bill", "Mar", 90])
table.add_row(["Alice", "April", 90])
print(table.get_string( sortby="Month"))
This produces the following:
+-----------------------+
| title test |
+-------+-------+-------+
| Name | Month | Grade |
+-------+-------+-------+
| Alice | April | 90 |
| Sally | Feb | 100 |
| Joe | Jan | 90 |
| Bill | Mar | 90 |
+-------+-------+-------+
I am trying to sort by the Month
column but since it is a string it is not treating it like a datetime
. Could you please advise how can i save a datetime object inside prettytable so i can sort it