Question: Here is the scenario. In your function you're executing statements using a cursor, but one of them fails and an exception is thrown. Your program exits out of the function before closing the cursor it was working with. Will the cursor float around taking up space? Do I have to close the cursor?

Additionally, the Python documentation has an example of cursor use and says: "We can also close the cursor if we are done with it." The keyword being "can," not "must." What do they mean precisely by this?

Answer: 
It's probably a good idea (although it might not matter much with sqlite, don't know there, but it'll make your code more portable). Further, with recent Python (2.5+), it's easy:

```
from __future__ import with_statement
from contextlib import closing

with closing(db.cursor()) as cursor:
    # do some stuff

```
Interestingly, the [Python 3.0 doc](https://docs.python.org/3.0/library/sqlite3.html) says "We can also close the cursor if we are done with it", while the [Python 2.7](https://docs.python.org/2.7/library/sqlite3.html) and [3.6](https://docs.python.org/3.6/library/sqlite3.html) doc says "We can also close the *connection* if we are done with it".

The Python 2.7 and 3.0-3.4 docs don't describe the cursor `.close()` method. But the Python 3.5 and 3.6 docs describe the [cursor `.close()`](https://docs.python.org/3.6/library/sqlite3.html#sqlite3.Cursor.close) method:

> 
> Close the cursor now (rather than whenever `__del__` is called).
> 
> 
> The cursor will be unusable from this point forward; a `ProgrammingError` exception will be raised if any operation is attempted with the cursor.
> 
> 
>