sqlite 3 attribute error __exit__

Sayth Renshaw flebber.crue at gmail.com
Sun May 15 22:21:23 EDT 2016


Hi

I have a file and want to create the sqlite3 db. Using with however i receive an attribute error and it causes an exit.

The relevant section of the file is:

import sqlite3

conn = sqlite3.connect("trial.db")
with conn, conn.cursor() as cur:
        # First, create tables.
    cur.execute("drop table if exists meetings, races, horses")
    cur.execute("create table meetings (" +
                ", ".join("%s varchar" % fld for fld in meetattrs)
                + ")")
    cur.execute("create table races (" +
                ", ".join("%s varchar" % fld for fld in raceattrs)
                + ")")
    cur.execute("create table horses (" +
                ", ".join("%s varchar" % fld for fld in horseattrs)
                + ")")


However it runs producing this error for line 30 which is
with conn, conn.cursor() as cur:

(pyXML) [sayth at manjaro pyXML]$ python racemeeting.py data/*xml
Traceback (most recent call last):
  File "racemeeting.py", line 31, in <module>
    with conn, conn.cursor() as cur:
AttributeError: __exit__

Why would i get this error?

Sayth



More information about the Python-list mailing list