Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'importing': 0.04; 'discard': 0.05; 'cursor': 0.09; 'func': 0.09; 'grp': 0.09; 'integer,': 0.09; 'nameerror:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'result.': 0.15; 'badge': 0.16; 'conn': 0.16; 'connect()': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.17; 'integer': 0.17; '"",': 0.22; 'defined': 0.22; 'tried': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'header:X-Complaints-To:1': 0.28; '>>>>': 0.29; 'error': 0.30; 'code': 0.31; 'file': 0.32; 'skip:s 30': 0.33; 'text,': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'table': 0.35; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'execute': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'gave': 0.65; 'subject:there': 0.65; 'subject': 0.66; 'below:': 0.71 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Is there a way to creat a func that returns a cursor that can be used? Date: Mon, 12 Nov 2012 11:57:52 +0100 Organization: None References: <05f7724a-1e41-43ea-b837-88e476917f9a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b48f.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352717997 news.xs4all.nl 6966 [2001:888:2000:d::a6]:57354 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33174 Khalid Al-Ghamdi wrote: > Is there a way to create a func that returns a cursor that can be used to > execute sql statements? You should read an introductory text on Python, this is not specific to sqlite3. > I tried this (after importing sqlite3), but it gave me the error below: > >>>> 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, subject text, course > text, ws text, date text, \ time text, proctor text, code text, no > integer,fl_time text, flag2 text, flag3 text, flag4 text, clash1 > integer, clash2 integer)") return cur >>>> connect() connect() returns a cursor, but you discard the result. Try cur = connect() > >>>> cur.execute("select * from schedule") > Traceback (most recent call last): > File "", line 1, in > cur.execute("select * from schedule") > NameError: name 'cur' is not defined