Question

I'm trying to translate this special character from is representation \u0096 to the character that I want to show. How can I do it? I tried different method using decode and encode method. Can you please help me?

Was it helpful?

Solution

If you are trying to use it in a json, you should use json.loads().

json.loads('"\u0096"')

Although with that said, I don't think that the encoded representation is the character that you mean it to be. I make - to be \u002d and your representation to be whitespace.

You can easily do this with larger strings from your files, for example:

>>> astring = "\u0048\u0065\u006c\u006c\u006f\u002c \u0077\u006f\u0072\u006c\u0064\u0021"
>>> new = json.loads(astring)
>>> new
'Hello, world!'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top