Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python and MySQLdb - Using DROP TABLE IF EXISTS seems to throw exception

Tags:

python

mysql

I got this code..

.....
try:
    task_db.cursor.execute('DROP TABLE IF EXISTS `tasks`')
    print "Affected: %d" % task_db.cursor.rowcount 
except MySQLdb.Error, e:
    print "Error ocurred: %s " % e.args[0]
    print e

If the tasks table doesn't exist, then I get a warning like

create_database.py:11: Warning: Unknown table 'tasks'

But if the table does exist then I wont get that warning. Odd?

like image 923
Wizzard Avatar asked Nov 10 '10 10:11

Wizzard


1 Answers

Catching the MySQLdb.Warning didn't work for me, so I found another way to suppress warnings:

import warnings
warnings.filterwarnings("ignore", "Unknown table.*")

And you can edit the second parameter with whatever you want to suppress.

like image 129
thomdask Avatar answered Sep 21 '22 13:09

thomdask