If I have the following code:
import sqlite
sqlite.connect('tmp.db').cursor().close()
I get the following error message:
Traceback (most recent call last):
File "searchengine2.py", line 13, in ?
sqlite.connect('tmp.db').cursor().close()
File "/usr/lib64/python2.4/site-packages/sqlite/main.py", line 280, in close
if self.con and self.con.closed:
ReferenceError: weakly-referenced object no longer exists
However, if I modify the code in the following way:
import sqlite
x1 = sqlite.connect('tmp.db')
x2 = x1.cursor()
x3 = x2.close()
everything is fine. Why?