Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.6Mb
PDF (A4) - 0.6Mb
EPUB - 136.5Kb
HTML Download (TGZ) - 85.5Kb
HTML Download (Zip) - 103.3Kb


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

User Comments
Sign Up Login You must be logged in to post a comment.