1

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

4
  • That's not a message, that's the return value. Commented Nov 6, 2012 at 16:36
  • @martin, Thanks. Can I suppress this value? Commented Nov 6, 2012 at 16:52
  • 1
    assign it to a variable? Why do you need to surpress it? Commented Nov 6, 2012 at 16:53
  • I am looping through a text file and inserting each record in the mysql table. For each cursor.execute(), I am getting this value, which is annoying in my case. But assigning to a variable may be a good idea. Commented Nov 6, 2012 at 16:55

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.