iteration - Iterating over resultset with comparison of column name - in python with Mysqldb -


i want use python populate database. have values out of table, calculate score , fill score anoter table. cant figure out how can compare column names of row resultset. because dont need of columns calculate, need few others id , type_name none calculation. want this:

cur = connection.cursor() query ="select * table" cur.execute(query) rs = cur.fetchall() row in rs:     col in row:         // if(col = "x" or col = "y" or col = "z"):                calc ...         // else:                use id, type_name whatever ... 

how can achieve this? else code blow bomb.

maybe searching answer too. of previous comment, solve that

field_names = cur.description  row in rs:     index, col in enumerate(row):         name = field_names[index][0]         if(name == "..."):         ...         elif(name == "..."):         ... 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -