I use PyMysql to connect to my MySQL DB.
cursor.execute(query)
data = cursor.fetchall()
for (id,clientid,timestamp) in cursor:
print id,clientid,timestamp
I want to sort the data based on timestamp ;like;
sortedList = sorted(data, key=lambda x: x.timestamp, reverse=False)
but cursor returns rows. How can I return the whole data, so I can sort them based on any parameter?
p.s: Here data contains multiple rows like;
1, '1170', 'AS0001', 1, '1', datetime.datetime(2018, 3, 15, 10, 56), Decimal('15185.7562'), Decimal('0.0000'), Decimal('19814.3181')
data
holds. Second, you probably want to sort on MySQL side, not in Python. – Corrugationkey=lambda x: x[5]
. I agree with @Corrugation though. – Quagmire