10.6.6 Класс cursor.MySQLCursorNamedTuple
Класс 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
))
© 2025 Oracle
Licensed under the GPLv2 License.