unicode and __repr__()

M

Martin Drautzburg

I am using repr() to pass arrays, dicts and combinations therof to
javascript as it already returns a valid javascript expression (a
string) right away. But for some reason it does not handle Umlaute
correctly and those characters finally appear as two strange characters
on the browser. I am using UTF-8 and assembling the string expression
manually works okay and the umlaute appear correctly in the browser (so
I could probably write my own serializer and it would work).

The commandline shows a difference too:
['ö'] <-- this is openbracket quote oumlaut quote closebracket
['\xf6']

It works okay for all other chars, just the umlaute seem to be a
problem.

How can I get __repr__() to handle the umlauter correctly, or is there
an easy way to postprocess the output ?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Martin said:
I am using UTF-8 and assembling the string expression
manually works okay and the umlaute appear correctly in the browser (so
I could probably write my own serializer and it would work).

That's what you should do. Or you can use one that people have already
written, e.g.

http://cheeseshop.python.org/pypi/simplejson

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top