Python use MySQL column names instead of numbers
Instead of:
cursor = conn.cursor()
cursor.execute("SELECT name, value FROM table")
result_set = cursor.fetchall()
for row in result_set:
print "%s, %s" % (row[0], row[1])
Just do this:
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT name, value FROM table")
result_set = cursor.fetchall()
for row in result_set:
print "%s, %s" % (row["name"], row["value"])
Nice to know and saved 3 lines of code!-)