我需要从mysql结果查询中获取字符串
mycursor.execute("Select text from text_table")
myresult = mycursor.fetchall()
rows=[i[0] for i in myresult]
for x in myresult:
print(x[0])
它仅返回一行,但以以下格式返回:
(u'I need this string',)
我尝试过
rows=[i[0] for i in myresult]
print(myresult)
答案 0 :(得分:0)
我认为您的语法已关闭。试试这个版本:
mycursor.execute("Select text from text_table")
myresult = mycursor.fetchall()
for row in myresult:
print(row[0])
令人反感的代码行可能是这样:
rows=[i[0] for i in myresult]
这似乎是通过遍历整个结果集来消耗游标。