简体   繁体   中英

How can I convert character like “\u0096” in python?

I'm trying to translate this special character from is representation 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?

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 \- 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!'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM