unicode and __repr__()
Martin Drautzburg
Martin.Drautzburg at web.de
Thu Apr 19 01:51:26 EDT 2007
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:
>>> print "["+"'ö'"+"]"
['ö'] <-- this is openbracket quote oumlaut quote closebracket
>>> print ["ö"].__repr__()
['\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 ?
More information about the Python-list
mailing list