I am trying to use cursor to execute a sql and convert the results to a dictionary
def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
This returns a value:
[{'created': datetime.datetime(2015, 12, 23, 4, 3, 53, 89779, tzinfo=<UTC>), 'to_address': 'Destination1', 'from_address': 'Source1', 'X': Decimal('0.0'), 'Y': Decimal('0.0')}]
I want it to be converted to a readable datetime format and take the decimal out. I want the output to be of the form
[{'created': 20150404T00:00:000000Z, 'to_address': 'Destination1', 'from_address': 'Source1', 'X': '0.0', 'Y': '0.0'}]
Appreciate any help on this.
- Shekar