Convert u "string" to "string" in Python without changing the encoding

I have the following:

u'\x96' 

I want to convert it to the following:

 '\x96' 

Is there any way to do this? str() does not work, and when using .encode(...) it changes the encoding. My main goal is to get the following result, so any shortcut to receive it will also be accepted:

 >>> '\x96'.decode("cp1252") u'\u2013' 

In other words, I have u'\x96' and I want u'\u2013' . Any help would be appreciated.

I am using Python 2.7.

+4
source share
2 answers
 u'\x96'.encode('raw_unicode_escape').decode("cp1252") 
+6
source

Latin-1 is an encoding that directly maps the first 256 Unicode characters to their byte values.

 >>> u'\x96'.encode('latin-1').decode("cp1252") u'\u2013' 
+3
source

All Articles