user1290426
user1290426

Reputation: 153

Error loading SQLite to Python

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?

Upvotes: 0

Views: 968

Answers (1)

CL.
CL.

Reputation: 180080

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.

Upvotes: 2

Related Questions