I have a mysql call:
zip = 48326
cursor.execute ("""
select distinct(name)
from usertab
where zip= %s
""" , (zip))
result = cursor.fetchall()
The result is returned in a tuple that looks like this:
result = (('alan',), ('bob',), ('steve',), ('tom',))
But I need a list like this:
mylist= ['alan', 'bob', 'steve', 'tom']
So I process the tuple into a list like this:
mylist = []
for row, key in enumerate(result):
for col, data in enumerate(key):
mylist.append(data)
This code works, but I'd like a simpler way.
How can I fetch a mysql single column result directly into a list?