I am trying to retrieve data from mysql table using python but keep getting an error. Please see my attempt below and the data:
import MySQLdb
# connect
db = MySQLdb.connect(host="localhost", user="root", passwd="xxxxxxx", db="world")
cursor = db.cursor()
t=['red', 'yellow']
for x in t:
cursor.execute("select * from mytable where colours=%s," [x])
I got the following error:TypeError: string indices must be integers, not str
I learnt Mysql stores data as tuples, hence I would need change %s to a tuple but don't know how.
Any suggestions? thanks.
cursor.execute("select * from mytable where colours=%s",[x])comma misplaced ?