Unicode/UTF-8 confusion

Carsten Haese carsten at uniqsys.com
Sat Mar 15 15:12:05 EDT 2008


On Sat, 2008-03-15 at 20:03 +0100, Carsten Haese wrote:
> On Sat, 2008-03-15 at 12:09 -0400, Tom Stambaugh wrote:
> > [...]
> > I use simplejson to serialize html strings that the server is delivering to 
> > a browser. Since the apostrophe is a string terminator in javascript, I need 
> > to escape any apostrophe embedded in the html.
> > [...]
> 
> simplejson escapes them for you:
> 
> >>> import simplejson
> >>> s = "    '    "
> >>> simplejson.dumps(s)
> '"    \'    "'
> 
> Why is this not good enough for your needs?

And before somebody else corrects my use of the word "escaping",
simplejson doesn't actually escape the apostrophe. The backslash is, of
course, python's repr() escaping the apostrophe. simplejson simply
handles the apostrophe by enclosing it in quotation marks. The result
should still be good enough, though.

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list