Is there a way to retrieve SQL result column value using column name instead of column index in Python? I’m using Python 3 with mySQL. The syntax I’m looking for is pretty much like the Java construct:
Object id = rs.get("CUSTOMER_ID");
I’ve a table with quite a number of columns and it is a real pain to constantly work out the index for each column I need to access. Furthermore the index is making my code hard to read.
Thanks!
The MySQLdb module has a DictCursor:
Use it like this (taken from Writing MySQL Scripts with Python DB-API):
edit: According to user1305650 this works for
pymysqlas well.