Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:help': 0.08; 'except:': 0.09; 'mask': 0.09; 'suggestions:': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'changes': 0.15; 'abort': 0.16; 'deletions': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'highlighted': 0.16; 'traceback.': 0.16; 'sat,': 0.16; 'all.': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'commit': 0.19; 'pointed': 0.19; 'command': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; "i've": 0.25; 'logging': 0.26; 'query': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'said,': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'program,': 0.31; 'code': 0.31; 'are.': 0.31; 'exceptions': 0.31; 'once,': 0.31; 'subject:some': 0.31; 'open': 0.33; 'could': 0.34; 'problem': 0.35; 'connection': 0.35; 'except': 0.35; 'problem.': 0.35; 'prepare': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'doing': 0.36; 'useful': 0.36; 'that,': 0.38; 'delete': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'entire': 0.61; 'course': 0.61; 'here': 0.66; 'biggest': 0.67; 'line,': 0.68; 'smith': 0.68; 'subject': 0.69; 'records': 0.73; '"learn': 0.84; 'bare': 0.84; 'describes': 0.84; 'toy': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=at1nntXsBphjeAmeS5UX+GhSwNI0u8V7UHAqGOHGtcY=; b=yCn2L/ccZhE4KNxpQ1S9c+Dr/XC/xWA05L8uN7KvD3q+rRdOvPAvEgZPo9qfYEAxZE cPzrFTY5f4oSPqhM0EsjMsKUiU+PTAdETk6Z9eT/TH/80+uV18o2rA2LqbcyhAFmj66i 5Xj2c4XpERb5uKavFdH6a2daT0TEXa7BFK/O7rEfuylhjbc/GqQG9wTI6x9uTt6zc4o3 mtHtBrztsKZ1zPpEy2ey7tqiikzx9Jk8h/A9B5vqkvzNuC/oGwjF70KADfFXham5Ahyu UiL4VvqwAA6BKg1TpidXPjyefy5v2RK0zN0PAPqz7NHMutIoqKAS5cW2Xe4G1OM9TJbg f+Xg== MIME-Version: 1.0 X-Received: by 10.50.138.195 with SMTP id qs3mr9386353igb.14.1407537373576; Fri, 08 Aug 2014 15:36:13 -0700 (PDT) In-Reply-To: References: Date: Sat, 9 Aug 2014 08:36:13 +1000 Subject: Re: Newbie needing some help From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407537382 news.xs4all.nl 2844 [2001:888:2000:d::a6]:37298 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75912 On Sat, Aug 9, 2014 at 5:07 AM, Matt Smith wrote: > # Prepare SQL query to DELETE required records > sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)" > try: > # Execute the SQL command > cursor.execute(sql) > # Commit your changes in the database > db.commit() > except: > # Rollback in case there is any error > db.rollback() By not even logging your errors, you mask everything that could go wrong. There is an error in the block of code that I've highlighted here, but the biggest problem is the bare except (as Mark pointed out). Suggestions: 1) Use a better subject line, which actually describes your problem. 2) As Mark said, don't use try/except here at all. Let exceptions abort the whole process with a nice useful traceback. 3) Open a database connection once, right at the top, and don't commit until the very end of your program. 4) If this isn't a toy program, consider doing the entire set of deletions in a single statement - it'll allow the database to do a single pass over the data. But if this is part of a "learn to use SQL" course or something, ignore that, keep going the way you are. ChrisA