MySQLdb + Python + quotes

Martin Skøtt mskott at image.dk
Wed May 10 00:14:00 CEST 2000


Lars Hoeyrup Jensen <robinhat at rhk.dk> writes:

> 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. I'm looking for something precisely
> like the Addslashes function in PHP; see this URL:

Sorry, I don't know any PHP, but I solved your problem by doing it
this way (I use PostgreSQL, but that shouldn't make a difference):
  titel = "'%s'" % form["titel"].value
The form dictionary is created by the cgi module. The principle is to
use string substitution and double quoting ("'  '").

-- 
Many regards
Martin Skøtt
mskott at image.dk

'In a certain sense, all decent programming languages are equally powerfull'
Dr. Alan Turing



More information about the Python-list mailing list