Python Undo Unicode Question

Let's say I have the following two variables:

bob1 = u'bob\xf0\xa4\xad\xa2'

and

bob2 = 'bob\xf0\xa4\xad\xa2'

How can I get the value of bob1 as the value of bob2. AKA, how do I expand Unicode formatting but save the escapped hex value?

If I do this:

bob1.encode('utf8')
'bob\xc3\xb0\xc2\xa4\xc2\xad\xc2\xa2'

It is not right...

Help!

0
source share
1 answer

The code points between the U + 0000 and U + 00FF cards correspond to the same byte value in ISO 8859-1 or Latin 1 encodings.

>>> u'bob\xf0\xa4\xad\xa2'.encode('latin-1')
'bob\xf0\xa4\xad\xa2'
+5
source

All Articles