sqlite 3 attribute error __exit__

Sayth Renshaw flebber.crue at gmail.com
Sun May 15 22:56:33 EDT 2016


On Monday, 16 May 2016 12:45:26 UTC+10, DFS  wrote:
> On 5/15/2016 10:21 PM, Sayth Renshaw wrote:
> > 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
> 
> 
> Answer #66 looks like the ticket:
> 
> http://stackoverflow.com/questions/7447284/how-to-troubleshoot-an-attributeerror-exit-in-multiproccesing-in-python
> 
> 
> Have you tried:
> 
> cur = conn.cursor()

cur = conn.cursor() does work thought I should have been able to use with to handle it for me.

Thanks

Sayth



More information about the Python-list mailing list