0

I'm trying to use SQLite with python and I'm going over examples from the python website. One example is to build a shell for SQLite: py

This is the beginning of the script

import sqlite3

con = sqlite3.connect(":memory:")
con.isolation_level = None
cur = con.cursor()

I'm loading the file from a text editor, and I'm confused by the error that I get when I import the file.

>>>import SQLoad
Traceback (most recent call last):
File"<stdin>", line 1, in <module>
File "SQLoad.py", line 1, in <module>
  c = conn.cursor()
NameError: name 'conn' is not defined

I'm confused because 'conn' isn't being defined in what I'm uploading. Is it something that has to be defined?

3
  • What do you mean by "I'm loading the file from a text editor"? Commented Oct 19, 2012 at 2:39
  • You're right, that isn't clear. I just meant that I have the file saved with the code for making the shell on it that I'm loading into python. Commented Oct 19, 2012 at 2:57
  • What is the first line in SQLoad.py? Commented Oct 19, 2012 at 3:06

1 Answer 1

2

Your first code block shows that the connection variable is named con.

The error message shows that you have written that variable as conn, and that this is in the first line of SQLoad.py, where the connection cannot have been opened yet.

Your first code block looks correct, but it is not what is actually stored in SQLoad.py.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.