Newbie needing some help

Matt Smith smithmm at tblc.org
Fri Aug 8 15:07:48 EDT 2014


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:
        #<do something with line>
        # 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140808/f023d955/attachment.html>


More information about the Python-list mailing list