Have a Sample Python List as Follows:
data = [
('Jane','dffd','sdas','sdas'),
('Jane','dffd','sdas','sdas'),
('Jane','dffd','sdas','sdas')
]
Tried inserting this list onto a My Sql database with tablename 'test' as Follows:
import MySQLdb as my
db = my.connect()
cursor = db.cursor()
data = [
('Jane','dffd','sdas','sdas'),
('Jane','dffd','sdas','sdas'),
('Jane','dffd','sdas','sdas')
]
ddt = str(data)
cursor.executemany('INSERT into test VALUES(%s, %s, %s,%s)' % ddt)
db.commit()
db.close()
Getting an error saying:
not enough arguments for format string
Table contains 4 columns : test1,test2,test3,test4 .I know Im making a silly mistake someplace, but can't seem to find it.
str(data)doesn't do what you think it does. Usecursor.executemany("INSERT into...)", data)instead. See also dev.mysql.com/doc/connector-python/en/… - DYZ