抑制光标.执行()python MySQLdb中的消息

2024-09-28 13:17:38 发布

您现在位置:Python中文网/ 问答频道 /正文

如何抑制光标.执行()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

我需要抑制这个“1L”信息


Tags: fromimport消息executedbconnectrootcursor
1条回答
网友
1楼 · 发布于 2024-09-28 13:17:38

您看到的不是警告消息,而是cursor.execute()的返回值。它是受影响的行数,1。在

API碰巧返回一个Python ^{} integer,但它与常规的int值相同:

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

如果不希望Python控制台将返回值回送给您,请将它们分配给一个变量:

^{pr2}$

相关问题 更多 >

    热门问题