Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'grp': 0.09; 'integer,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'tutorials,': 0.09; 'def': 0.10; 'backslashes': 0.16; 'badge': 0.16; 'conn': 0.16; 'connect()': 0.16; 'fine.': 0.16; 'newlines': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sqlite3': 0.16; 'subject: \n ': 0.16; 'whitespace.': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'jan': 0.18; 'suggested': 0.20; 'import': 0.21; 'needed.': 0.23; 'specifically': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'functions.': 0.27; 'header:X -Complaints-To:1': 0.28; 'chris': 0.28; 'prints': 0.29; 'statements': 0.29; 'yesterday.': 0.29; 'code': 0.31; 'point': 0.31; 'running': 0.32; 'skip:s 30': 0.33; 'text,': 0.33; 'to:addr :python-list': 0.33; 'skip:: 10': 0.35; 'table': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'different': 0.63; 'note:': 0.64; 'gave': 0.65; 'subject:there': 0.65; 'subject': 0.66; '7:25': 0.84; 'received:fios.verizon.net': 0.84; 'treats': 0.84; 'joel': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Is there a way to creat a func that returns a cursor that can be used? Date: Mon, 12 Nov 2012 15:41:35 -0500 References: <05f7724a-1e41-43ea-b837-88e476917f9a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352752925 news.xs4all.nl 6889 [2001:888:2000:d::a6]:52531 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33197 On 11/12/2012 7:25 AM, Joel Goldstick wrote: > Chris gave you the same help that you got yesterday. ... > go to ://python.org> and read the tutorials, > specifically about functions. It is hard to see what is working and not with an empty database. But to drive the point home, running 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, 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 cur = connect() print(cur.fetchone()) cur.execute("select * from schedule") print(cur.fetchall()) # prints None [] So the change suggested by multiple people *does* work ;-). On a different note: use triple quote for multi-line strings and backslashes are not needed. 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)''') works fine. SQL treats newlines in statements as whitespace. -- Terry Jan Reedy