sqlite 3 attribute error __exit__

Ben Finney ben+python at benfinney.id.au
Sun May 15 22:52:01 EDT 2016


Sayth Renshaw <flebber.crue at gmail.com> writes:

> with conn, conn.cursor() as cur:

What are you expecting this ‘with’ statement to do?

As you've written it, the statement declares your intent to enter both
‘conn’ and ‘conn.cursor()’ as context managers.

    <URL:https://docs.python.org/3/reference/compound_stmts.html#with>

To “enter a context manager” entails calling the ‘__enter__’ method on
the context manager object. So that will happen to both ‘conn’ and
‘conn.cursor()’.

Are both of those objects context managers? If not, you will get the
error that you reported.

-- 
 \         “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\    Brain, but if we get Sam Spade, we'll never have any puppies.” |
_o__)                                           —_Pinky and The Brain_ |
Ben Finney




More information about the Python-list mailing list