1

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...

Help!

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
Nick
  • 2,913
  • 12
  • 40
  • 52

1 Answers1

6

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'
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358