New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement context manager for Cursors #190

gvenzl opened this Issue Jun 20, 2018 · 1 comment


None yet
2 participants
Copy link

gvenzl commented Jun 20, 2018

Implement context manager for Cursor object to enable with statement.
Currently the with statement can't be used for cursors because they don't implement a context manager, i.e. the __enter__ and __exit__ attributes meaning that the following code will fail:

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

  File “/Users/gvenzl/test/”, line 23, in test
    with conn.cursor() as c:
AttributeError: __exit__

It would make sense to enable cursor object to be used in with statements that take care of closing the cursors automatically.

@gvenzl gvenzl added the enhancement label Jun 20, 2018


This comment has been minimized.

Copy link

anthony-tuininga commented Jun 21, 2018

I agree that it would make sense to implement the context manager on cursors. Thanks @gvenzl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment