mysql - python:type error while connection -


this question exact duplicate of:

enter image description here got error on code

    if rows[0] in line: typeerror: 'in <string>' requires string left operand, not tuple 

my code:

import mysqldb  db = mysqldb.connect(host="localhost", # host, localhost                          user="root", # username                           passwd="mysql", # password                           db="sakila") # name of data base cursor = db.cursor()      # execute sql select statement cursor.execute("select student myclass") rows=cursor.fetchall()    open('qwer.txt','r') file:     line in file:         row in rows:             if rows[0] in line:                stmt="select english marks student = :student"                cursor.execute(stmt,dict(student=row[0]))                print "english marks:",cursor.fetchall()[0][0] 

please help,since doesnot provide me output no errors

you using rows[0] meant use row[0] instead:

for row in rows:     if row[0] in line: 

rows list of tuples, rows[0] first such tuple. row[0] first column in current row (e.g. student column select).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -