for row in cur.execute("select business_id,count(text) from reviews group by business_id"):
此返回哪种类型的变量?row
是元组还是列表?如何使用row
元素将其变成字符串并将其切成较小的字符串?
它返回元组。根据Cursor.fetchone((的MySQL连接器文档:
此方法检索了查询结果集的下一行,并返回单个序列,或者如果没有更多行可用,则无。默认情况下,返回的元组由MySQL Server返回的数据组成,转换为Python对象。
...
fetchone((方法由fetchall((和fetchmany((使用。当将光标用作迭代器时也使用。
您可以通过索引访问列。
for row in cur.execute("select business_id,count(text) from reviews group by business_id"):
id = row[0]
count = row[1]
# Use id and count here