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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With