2012-11-06 55 views
1

如何在MySQLdb中抑制cursor.execute()消息。在python MySQLdb中抑制cursor.execute()消息

>>> 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 

我需要抑制這種「1L」消息

+0

這不是一條消息,那是*返回值*。 –

+0

@馬丁,謝謝。我能壓制這個值嗎? – Curious

+1

將它分配給一個變量?你爲什麼需要抑制它? –

回答

1

你看到的沒有一個警告信息,但cursor.execute()返回值。這是受影響的行數,1

的API恰好返回一個Python long integer,但它的其他方面與常規int值:

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

如果你不想Python的控制檯來呼應返回值給你,將它們分配給一個變量:

>>> somevariable = 1L