MySQL Connector/Python 发行说明
MySQLCursorNamedTuple
类继承自 MySQLCursor
。此类从 Connector/Python 2.0.0 开始可用。
一个 MySQLCursorNamedTuple
游标将每行作为命名元组返回。每个命名元组对象的属性是 MySQL 结果的列名。
示例
cnx = mysql.connector.connect(database='world')
cursor = cnx.cursor(named_tuple=True)
cursor.execute("SELECT * FROM country WHERE Continent = 'Europe'")
print("Countries in Europe with population:")
for row in cursor:
print("* {Name}: {Population}".format(
Name=row.Name,
Population=row.Population
))