Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:help': 0.08; 'cursor': 0.09; 'except:': 0.09; 'rows': 0.09; 'sql,': 0.09; 'try:': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'changes': 0.15; 'debugger,': 0.16; 'disconnect': 0.16; 'missing?': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'commit': 0.19; 'skip:f 30': 0.19; 'command': 0.22; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'query': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'getting': 0.31; 'are.': 0.31; 'seemingly': 0.31; 'subject:some': 0.31; 'file': 0.32; 'skip:m 30': 0.32; 'run': 0.32; 'text': 0.33; 'open': 0.33; 'fri,': 0.33; 'skip:# 10': 0.33; 'connection': 0.35; 'prepare': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'method': 0.36; 'server': 0.38; 'pm,': 0.38; 'anything': 0.39; 'delete': 0.39; 'skip:u 10': 0.60; "you'll": 0.62; 'smith': 0.68; 'records': 0.73; 'cut': 0.74; 'apparent': 0.91 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:to :cc:content-type; bh=Z9X3t+VGQDCg+0Xd1bmlCmlrkXmOvaAX1P1aM25XRrI=; b=J0eGqLliBEuKPkYstN6iGVSumZephFOOGbWZNefdu/5LvtdCtCuhmXSxHbiOD0LkaP f9kqAZSa+yc5+rK8cP/1bMMGYw7Pb4wBYYpvWgKLLoFH4IXqDFUYzzH3+7Z41FAkDpqA iN+Tyov08qsFAmd9eamT8SaF5kxctS2i6XEljKsAuFz9a8aKlxeoP9H9Z0HdBG8lABVx kmViaMuwjFZeCqNs79HtnZxiw4zc3R/X/5K7gyZMrAtVcuXt5BZiyDnVP6iiGAxKZ9yr igLSaPfLe6Ax9/nHcPc69IE9xuFVxteXh6MksfRoT6aPnp7mRQ8cQMzRApDuLj6Zg05e RJBw== MIME-Version: 1.0 X-Received: by 10.194.62.104 with SMTP id x8mr10309356wjr.7.1407534235104; Fri, 08 Aug 2014 14:43:55 -0700 (PDT) In-Reply-To: References: Date: Fri, 8 Aug 2014 17:43:55 -0400 Subject: Re: Newbie needing some help From: Larry Martell To: Matt Smith Content-Type: text/plain; charset=UTF-8 Cc: "python-list@python.org" 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407534242 news.xs4all.nl 2935 [2001:888:2000:d::a6]:49216 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75907 On Fri, Aug 8, 2014 at 3:07 PM, Matt Smith wrote: > I am trying to write a program that will loop through a text file and delete > rows in a mysql database. > > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > > This is the code: > #!/usr/bin/python > import mysql.connector > # > f=open('/home/smithm/email-list.txt', 'r') > for line in f: > # > # Open database connection > db = mysql.connector.connect(user="xx", password="xx", > host="localhost", database="xx") > > # prepare a cursor object using cursor() method > cursor = db.cursor() > > # 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() > > # disconnect from server > db.close() Run it in the debugger, set a BP after you create the sql, print it out, and cut and paste it into an interactive sql session and you'll see what the issues are.