MySQL Connector/Python Release Notes
Syntax:
sequence = cursor.column_names
This read-only property returns the column names of a result set as sequence of Unicode strings.
The following example shows how to create a dictionary from a
tuple containing data with keys using
column_names
:
cursor.execute("SELECT last_name, first_name, hire_date "
"FROM employees WHERE emp_no = %s", (123,))
row = dict(zip(cursor.column_names, cursor.fetchone()))
print("{last_name}, {first_name}: {hire_date}".format(row))
Alternatively, as of Connector/Python 2.0.0, you can fetch rows as dictionaries directly; see Section 10.6.4, “cursor.MySQLCursorDict Class”.