Let's say I have the following two variables:
bob1 = u'bob\xf0\xa4\xad\xa2'
bob2 = 'bob\xf0\xa4\xad\xa2'
How can I get the value of bob1
to be the value of bob2
? That is, how do I unroll the unicode formatting but keep the escapped hex value?
If I do this:
bob1.encode('utf8')
'bob\xc3\xb0\xc2\xa4\xc2\xad\xc2\xa2'
That's not right开发者_Python百科...
Help!
Code points between U+0000 and U+00FF map to the same byte value in the ISO 8859-1 or Latin 1 encodings.
>>> u'bob\xf0\xa4\xad\xa2'.encode('latin-1')
'bob\xf0\xa4\xad\xa2'
精彩评论