简体   繁体   中英

Suppress cursor.execute() message in python MySQLdb

How to suppress the cursor.execute() message in MySQLdb.

>>> from warnings import filterwarnings
>>> import MySQLdb
>>> filterwarnings('ignore', category = MySQLdb.Warning)
>>> db = MySQLdb.connect('127.0.0.1', 'root', '','')
>>> cursor = db.cursor()
>>> cursor.execute("select version()")
1L

I need to suppress this '1L' message

What you see there is not a warning message, but the return value of cursor.execute() . It's the number of rows affected, 1.

The API happens to return a Python long integer , but it's otherwise the same as a regular int value:

>>> 1L
1L
>>> 1
1
>>> 1 == 1L
True

If you do not want the Python console to echo return values back to you, assign them to a variable:

>>> somevariable = 1L

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM