Is there a way to retrieve SQL result column value using column name instead of column index in Python?
result = `select name, deptname from employee;`
I tried below one:
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT name, category FROM animal")
result_set = cursor.fetchall()
for row in result_set:
print "%s, %s" % (row["name"], row["deptname"])
Here I got an error like:
TypeError: tuple indices must be integers, not str
Any help will be awesome?