为什么 sql 查询提取其他信息
Why sql query extract other info
我想从我的数据库中获取城市属性。但是当我 运行 我的代码时,我得到了这个信息 (u'Rome',)
我只想得到 Rome
结果
这是我的代码
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
为什么我得到这个 (u'Rome',)
结果而不仅仅是 Rome
?
谢谢
返回列表中的每个 record
都由一个 tuple
表示,即使只有一个 column
,要访问该列,请使用其索引:
for res in myresult:
print res[0]
或者将元组解压为变量:
for (city,) in myresult:
print city
我想从我的数据库中获取城市属性。但是当我 运行 我的代码时,我得到了这个信息 (u'Rome',)
我只想得到 Rome
结果
这是我的代码
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
为什么我得到这个 (u'Rome',)
结果而不仅仅是 Rome
?
谢谢
返回列表中的每个 record
都由一个 tuple
表示,即使只有一个 column
,要访问该列,请使用其索引:
for res in myresult:
print res[0]
或者将元组解压为变量:
for (city,) in myresult:
print city