[DB-SIG] Context manager support for cursors
Gerald Venzl
gerald.venzl at oracle.com
Wed Jun 20 23:47:41 EDT 2018
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)
Currently this results in an AttributeError:
File “/Users/gvenzl/test/test.py”, line 23, in test
with conn.cursor() as c:
AttributeError: __exit__
Thx,
---------------
Gerald Venzl | Senior Principal Product Manager
Email: gerald.venzl at oracle.com <mailto:gerald.venzl at oracle.com> | Phone: +1.650.633.0085 <tel:+16506330085>
Oracle ST & Database Development
400 Oracle Parkway | Redwood Shores | 94065 | USA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20180621/8bf720e6/attachment.html>
More information about the DB-SIG
mailing list