Is __enter__ and __exit__ behaviour for connection objects specified in the Python database API?

后端 未结 2 1730
逝去的感伤
逝去的感伤 2021-01-02 04:01

Background

I recently discovered the Python with keyword and started seeing its potential usefulness for more prettily handling some scenarios where I

2条回答
  •  情深已故
    2021-01-02 04:54

    See the __enter__ function in this link. https://github.com/PyMySQL/mysqlclient-python/blob/master/MySQLdb/connections.py

    __enter__ function of connection object returns self.cursor().

    That is why you are getting cursor object instead of Connection object.

提交回复
热议问题