How to hide warning about drop table message to MariaDB
Python
python at invalid
Sun Jan 19 10:35:33 EST 2020
^Bart wrote:
> I ran this code:
>
> #!/usr/bin/python
> import MySQLdb
>
> # Open database connection
> db = MySQLdb.connect("localhost","root","MyPwd","MyDB")
>
> # prepare a cursor object using cursor() method
> cursor = db.cursor()
>
> # Drop table if it already exist using execute() method.
> cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
>
> # Create table as per requirement
> sql = """CREATE TABLE EMPLOYEE (
> FIRST_NAME CHAR(20) NOT NULL,
> LAST_NAME CHAR(20),
> AGE INT,
> SEX CHAR(1),
> INCOME FLOAT )"""
>
> cursor.execute(sql)
>
> # disconnect from server
> db.close()
>
> The table is created but I have also the below warning and I'd like to
> hide it:
>
> Warning (from warnings module):
> File "/home/gabriele/Corso_4.0/Python/MySQL_create_table.py", line 11
> cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
> Warning: (1051, "Unknown table 'gabfood.EMPLOYEE'")
> >>>
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# your code
More information about the Python-list
mailing list