Newbie problem inserting into MySQL

Peter Otten __peter__ at web.de
Mon Aug 18 16:35:39 EDT 2008


len wrote:

> I have started a little pet project to learn python and MySQL.  The
> project involves figuring out all the combinations for a 5 number
> lottery and storing the data in a MySQL file.

> import MySQLdb

>                         cursor.executemany('''insert into
> littlelottery
>                         values (?,?,?,?,?,?,?,?,?)''', listofrec)

> i get the following error on insert;
> raise errorclass, errorvalue
> TypeError: not all arguments converted during string formatting
> Script terminated.
> 
> Do I have to covert all of the fields in the tuple records to string
> or what?

>>> import MySQLdb
>>> MySQLdb.paramstyle
'format'

So it looks like you need to replace the '?' in your SQL statement
with '%s'.

Peter



More information about the Python-list mailing list