我在 Python 中有一个查询,当我使用 row = cur.fetchone()
或 rows = cur.fetchall()
时,我无法正确解压值。
import pymysql.cursors
cur.execute(QUERY)
rows = cur.fetchall()
for row in rows:
col1_data, col2_data, col3_data = row
我希望 col#_data
包含相应的值,但它只有标签。如果我执行 print(row)
我得到:
{'post_author': 'USERNAME', 'newposts': Decimal('52'), 'reposts': Decimal('50')}
如何解压 mysql 值?
最佳答案
像字典一样访问行
:
for row in rows:
post_author = row['post_author']
newposts = row['newposts']
reposts = row['newposts']
关于Python MySQL 解压 cur.fetchall() 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50244737/