I couldn’t find a solution on how to easily format the result of a query.
x
cursor.execute("SELECT name, email FROM customers")
print(cursor.fetchone())
>>> [('Joe Bloggs', 'joebloggs@jbloggs.com')]
I would like the result to be formatted in a way like:
- Name : Joe Bloggs
- Email : joebloggs@jbloggs.com
Advertisement
Answer
row = cursor.fetchone()[0] #get the only element in array
name = row[0]
email = row[1]
And then you can use name and email to format your result. You also need to look out for when your query returns 0 elements.