【发布时间】:2012-10-26 15:56:39
【问题描述】:
如何在 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”消息
【问题讨论】:
-
这不是消息,这是返回值。
-
@martin,谢谢。我可以抑制这个值吗?
-
把它赋值给一个变量?为什么需要压制它?
-
我正在遍历一个文本文件并将每条记录插入 mysql 表中。对于每个 cursor.execute(),我都会得到这个值,这在我的情况下很烦人。但是分配给变量可能是个好主意。
标签: python cursor mysql-python