^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
--
https://mail.python.org/mailman/listinfo/python-list