mysql - python:type error while connection -
this question exact duplicate of:
- connecting 2 tables python [closed] 2 answers
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
Post a Comment