Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4a.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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:help': 0.08; 'cursor': 0.09; 'except:': 0.09; 'rows': 0.09; 'try:': 0.09; 'runs': 0.10; 'changes': 0.15; 'disconnect': 0.16; 'missing?': 0.16; 'trying': 0.19; 'commit': 0.19; 'skip:f 30': 0.19; 'command': 0.22; 'import': 0.22; 'error': 0.23; 'query': 0.26; 'code:': 0.26; 'message-id:@mail.gmail.com': 0.30; 'getting': 0.31; 'seemingly': 0.31; 'subject:some': 0.31; 'file': 0.32; 'skip:m 30': 0.32; 'text': 0.33; 'open': 0.33; 'skip:# 10': 0.33; 'skip:d 20': 0.34; 'received:209.85': 0.35; 'connection': 0.35; 'something': 0.35; 'prepare': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'method': 0.36; 'received:209': 0.37; 'server': 0.38; 'skip:m 40': 0.38; 'to:addr :python-list': 0.38; 'anything': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; '8bit%:10': 0.64; 'skip:m 50': 0.68; 'smith': 0.68; 'records': 0.73; 'apparent': 0.91 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=5cqkMzPSoIXGVhGKFbTZksVLmeM4LtHWWPpGUwET5EM=; b=N8OuKBfUkh+moWXBELViMWjrF548sx4dvYCb20cF5kh1godeKFthr5klFjJMa9RF+Z ap52+jcgGpsElQnJpyqygryUF9dfWX0KtrjHFqyq14nnR9KQFRJ7i2OxDmkq0d9VqT4P AJEC7jsb5YvwE62nDs6s6MRWjN8QeiRnQLwnqNBfmLMFhFj3Vlke9jki2G8pVB20sBom zs8vNbvZ4/Ysy2HTo5SlEv9ncTWdzsKCGVgi62mfb1lQy51+RNc/+UuTvydRaCpSBPWP ds65fXji39XvoiNMCudgkk470lzDs0vqjFNlzCGgcX8SGhOI2K29q5pqmHeCiIk0USHf XHdg== X-Gm-Message-State: ALoCoQmvw+jPk20XVxOz3qakCnPzgD+sHnxIfhOQ0SRAX+uEHQliHoi8wwNuDOuhTeAohFa2d3Hz X-Received: by 10.224.173.7 with SMTP id n7mr42025454qaz.57.1407524898730; Fri, 08 Aug 2014 12:08:18 -0700 (PDT) MIME-Version: 1.0 From: Matt Smith Date: Fri, 8 Aug 2014 15:07:48 -0400 Subject: Newbie needing some help To: python-list@python.org Content-Type: multipart/alternative; boundary=047d7b5da6c79a103c050022ed91 X-Mailman-Approved-At: Fri, 08 Aug 2014 23:38:35 +0200 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: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407533916 news.xs4all.nl 2935 [2001:888:2000:d::a6]:46536 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75906 --047d7b5da6c79a103c050022ed91 Content-Type: text/plain; charset=UTF-8 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() -- Matthew Smith --047d7b5da6c79a103c050022ed91 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I am trying to write a program that will loop through a te= xt 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=3Dopen('/home/smithm/email-list.txt&#= 39;, 'r')
for line in f:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 #<do something= with line>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Open database connec= tion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 db =3D mysql.connector.connect(u= ser=3D"xx", password=3D"xx", host=3D"localhost&quo= t;, database=3D"xx")

=C2=A0 =C2=A0 =C2=A0 =C2=A0 # prepare a cursor object u= sing cursor() method
=C2=A0 =C2=A0 =C2=A0 =C2=A0 cursor =3D db.cu= rsor()

=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Prepare SQL q= uery to DELETE required records=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0= sql =3D "DELETE FROM tblc_users WHERE user_email=3D%s, % (line)"=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 # Execute the SQL command
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 cursor.execute(sql)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Comm= it your changes in the database
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 db.commit()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 except:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Rollback in case there is any err= or
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 db.rollback()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 # disconnect from server
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 db.close()

--
Matthew Smith

--047d7b5da6c79a103c050022ed91--