Say I have a MySQL table I access through MySQLDB. I have a standard
SELECT statement:
sql = "SELECT * FROM EMPLOYEE \
WHERE INCOME > '%d'" % (1000)
I then execute it with the cursor and pluck out the columns as below.
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
Is it possible to assign all the column names in a single statement? Something like:
for row in results:
fname, lname, age, sex, income = unpack(row)
I could always do:
fname, lname, age, sex, income = row[0], row[1], row[2], row[3], row[4]
But I have over 30 columns in my table and this is getting painful. Note that though I'm using MySQL right now, I'd like this to be as DB agnostic as possible; our benevolent overlords might decide to port everything over to another database at any point.