On 06/21/2018 01:31 AM, Gerald Venzl wrote:
Hi all,

I was wondering whether there has been any particular reason that the specification of the Cursor object doesn’t implement a context manager to enable for example the “with” statement? Being able to use the “with” statement for database cursors, just like other external resources like files, etc., I think makes a lot of sense:

with conn.cursor()as c:
     c.execute("SELECT 'test' from dual")
     result = c.fetchall()
     print(result)

It does (make sense). The explanation is that context managers did not exist when the PEP was written. An update is long overdue, IMHO.

federico
_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
https://mail.python.org/mailman/listinfo/db-sig

Reply via email to