I want get city attribute from my database. But when I run my code I get this info (u'Rome',)
I want get only Rome
as result
This is my code
x
connection = mysql.connector.connect(
host="",
database="",
user="",
passwd="")
mycursor = connection.cursor()
mycursor.execute ("SELECT City FROM home limit 1")
myresult=mycursor.fetchall()
for res in myresult:
print res
Why do I get this (u'Rome',)
result and not only Rome
?
Thanks
Advertisement
Answer
Every record
in the returned list is represented by a tuple
even if There is only one column
, to access the column use its index:
for res in myresult:
print res[0]
Or unpack the tuple to variables:
for (city,) in myresult:
print city