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
))