'mysql.connector.connect()'是否支持'with'块?

时间:2020-02-14 13:05:21

标签: python mysql

根据文档one two,我们每次连接时都应关闭连接器。

import mysql.connector

cnx = mysql.connector.connect(**config)
# do some stuff
cnx.close()

它支持with界面来执行以下操作吗?:

with mysql.connector.connect(**config):
    #do some stuff

0 个答案:

没有答案