[Tutor] Connecting to a DB via a function call

Khalid Al-Ghamdi emailkgnow at gmail.com
Sun Nov 11 12:39:42 CET 2012


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


   1. import csv
   2. import sqlite3
   3.
   4. def connect():
   5.     conn = sqlite3.connect(':memory:')#use sch3.db or sch4.db  ....
   etc.
   6.     cur = conn.cursor()
   7.     cur.execute("create table schedule (teams integer, sn integer,
   badge integer ,name text, grp integer,\
   8.    major text, track text, stage text,  tc text)")
   9.
   10. connect()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121111/8f5827b1/attachment.html>


More information about the Tutor mailing list