Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb


10.6.6 cursor.MySQLCursorNamedTuple Class

The MySQLCursorNamedTuple class inherits from MySQLCursor. This class is available as of Connector/Python 2.0.0.

A MySQLCursorNamedTuple cursor returns each row as a named tuple. The attributes for each named-tuple object are the column names of the MySQL result.

Example:

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