string escaping problems with MySQLdb
Edward C. Jones
edcjones at erols.com
Tue Jan 9 09:45:05 EST 2001
BxT wrote:
> Hi, i know this is a new-bie question,
Not a newbie question. A difficult question.
>
> i'm using MySQLdb and, as i'm extracting records, i get string escaped as
> follows:
> for example, instead of ß i'm getting \\337 (yes, with doppel \). When i'm
> printing the string i'm getting blah\337 (internally is blah\\337). I tried
> to use string.replace but it's giving me the same string. Is there a way to
> print blahß?
> For now, thanks in advance,
> BxT
I have never understood the MySQL / MySQLdb escaping rules. Therefore I encode
the data before storing it. None of the characters in base64 output need to be
escaped.
nice_data = base64.encodestring(raw_data)
raw_data = base64.decodestring(nice_data)
Since my data are large Python objects, I also pickle and compress them:
nice_data = base64.encodestring(zlib.compress(cPickle.dumps(python_object)))
python_object = cPickle.loads(zlib.decompress(base64.decodestring(nice_data)))
Good luck,
Ed Jones
More information about the Python-list
mailing list