Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75906
| From | Matt Smith <smithmm@tblc.org> |
|---|---|
| Date | 2014-08-08 15:07 -0400 |
| Subject | Newbie needing some help |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12762.1407533916.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Newbie needing some help Matt Smith <smithmm@tblc.org> - 2014-08-08 15:07 -0400
Re: Newbie needing some help John Gordon <gordon@panix.com> - 2014-08-09 02:51 +0000
Re: Newbie needing some help Chris Angelico <rosuav@gmail.com> - 2014-08-09 13:03 +1000
csiph-web