Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75906

Newbie needing some help

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 <smithmm@tblc.org>
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 <smithmm@tblc.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12762.1407533916.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[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 | NextNext in thread | Find similar | Unroll thread


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