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

User Comments
Add your own comment.