[Tutor] Connecting to a DB via a function call

Norman Khine norman at khine.net
Sun Nov 11 12:45:19 CET 2012


hi

On Sun, Nov 11, 2012 at 11:39 AM, Khalid Al-Ghamdi <emailkgnow at gmail.com> wrote:
> Hi,
>
> Why is it that the following even though I call the below function? And how
> do I write a function that makes connection that I can use to query my DB?
>
> Traceback (most recent call last):
>   File "C:/Python33/My Stuff/schedule_machine/schedule_machine01.py", line
> 19, in <module>
>     cur.execute('INSERT INTO schedule \
> NameError: name 'cur' is not defined
>
> import csv
> import sqlite3
>
> def connect():
>     conn = sqlite3.connect(':memory:')#use sch3.db or sch4.db  .... etc.
>     cur = conn.cursor()
>     cur.execute("create table schedule (teams integer, sn integer, badge
> integer ,name text, grp integer,\
>    major text, track text, stage text,  tc text)")
>
> connect()
>

try this http://docs.python.org/2/library/sqlite3.html

>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )


More information about the Tutor mailing list