MySQLdb + Python + quotes

Fredrik Lundh effbot at
Tue May 9 18:33:52 EDT 2000

Lars Hoeyrup Jensen <robinhat at> wrote:
> I use the MySQLdb module to make Python interact with MySQL. I have a
> problem, when I try to insert strings that contain special characters
> (here I primarily think of quotes: ' and "). There _must_ be a smart
> way to escape these characters.

from the recent "BLOBS and python" thread:


    From: Oleg Broytmann <phd at>
    Date: Fri, 5 May 2000 08:26:36 +0000 (GMT)
    Subject: Re: BLOBS and python

    On Thu, 4 May 2000, sp00fD wrote:
    > con.execute("INSERT INTO foo (myblob) VALUES ('%s')" % image)

    con.execute("INSERT INTO foo (myblob) VALUES ('%s')" % MySQL.escape(image))
                                                           ^^^^^^^^^^^^ !!!


hope this helps!


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list