[Tutor] what is wrong with this code?

Serdar Tumgoren zstumgoren at gmail.com
Mon Apr 26 19:18:54 CEST 2010

> user_tables = ['notification', 'userNotification', 'product_comments',
> 'product_donation_paypalTransaction', 'product_donation',
> 'productList_recommended', 'productList_user_assoc',
> 'profile_values']
> drop_user_tables = """DROP TABLE IF EXISTS db2.%s"""
> try:
>    cursor.execute(drop_user_tables, (x for x in user_tables))

It looks like what you're after is the cursor's "executemany" method, which
is supported by many common database adapters that comply with DB-API2.0.

If you're using sqlite3, there are more details here:


In your code, you seem to be trying to loop over the values in the
user_tables list. I haven't tested this, but instead try simply passing the
list of user_tables to executemany:

    cursor.executemany(drop_user_tables, user_tables)

If the above doesn't work or is not available with your database adapter,
how about just using a simple loop?

for table in user_tables:
    cursor.execute(drop_user_tables, (table,))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100426/e5f08bdf/attachment-0001.html>

More information about the Tutor mailing list