I am trying to extract data from a database and assign them to different lists. this particular error gives me a lot of problems "TypeError: tuple indices must be integers, not str" I tried to convert it to float, etc., but without success.
the code goes below
conn=MySQLdb.connect(*details*) cursor=conn.cursor() ocs={} oltv={} query="select pool_number, average_credit_score as waocs, average_original_ltv as waoltv from *tablename* where as_of_date= *date*" cursor.execute(query) result=cursor.fetchall() for row in result: print row ocs[row["pool_number"]]=int(row["waocs"]) oltv[row["pool_number"]]=int(row["waoltv"])
Example output for printing:
('MA3146', 711L, 81L) ('MA3147', 679L, 83L) ('MA3148', 668L, 86L)
and this is the exact error I get:
ocs[row["pool_number"]]=int(row["waocs"]) TypeError: tuple indices must be integers, not str
Any help would be appreciated! thank you people!
python sql database
Harsha jasti
source share