Python mysql连接器返回元组

我通过
mysql连接器连接到
mysql数据库并运行一个简单的查询来提取ID列表.我需要遍历该列表并将它们传递给其他代码.出于某种原因,我得到了一个元组列表.这是预期的行为吗?如果没有,我做错了什么?

这是我的代码的片段:

import mysql.connector
conn = mysql.connector.connect(host='127.0.0.1', database='t', user='r', password='pwd')
cursor = conn.cursor()
query = ( "select id from T where updated < '%s'" % (run_date) )
cursor.execute(query)
for row in cursor:
   print (row)

cursor.close()

我得到以下回复(来自d / b中的INT字段):

(Decimal('991837'),)
(Decimal('991838'),)
(Decimal('991839'),)
(Decimal('991871'),)
(Decimal('991879'),)
(Decimal('991899'),)
(Decimal('992051'),)
(Decimal('992299'),)
(Decimal('992309'),)

最佳答案 是的,这是预期的行为.将游标用作可迭代基本上等效于使用fetchone()方法对其进行循环.从
documentation for fetchone()(强调我的):

This method retrieves the next row of a query result set and returns a
single sequence, or None if no more rows are available. By default,
the returned tuple consists of data returned by the MySQL server,
converted to Python objects. If the cursor is a raw cursor, no such
conversion occurs;

点赞