0

I have these variables:

s1 = '\xd1\x98\xd1\x83\xd0\xbd'
s2 = u'\xd1\x98\xd1\x83\xd0\xbd'

How can I transform variable s2 to be same as s1 so that comparing both will return True.

user2136786
  • 305
  • 2
  • 3
  • 11
  • Ooops, found the answer right here that solves the problem: http://stackoverflow.com/questions/11174790/convert-unicode-string-to-byte-string But why should I encode to Latin-1 when text is in Cyrillic? Or better, why doesn't `s2.encode('windows-1251')` work? – user2136786 Jun 21 '13 at 04:12
  • That looks to me to be UTF-8, `u'\u0458\u0443\u043d'`, `јун`. – Chris Morgan Jun 21 '13 at 04:18
  • This is already posted in Stackoverflow. Check here: http://stackoverflow.com/questions/11174790/convert-unicode-string-to-byte-string – vkrams Jun 21 '13 at 04:19

1 Answers1

3

You can convert s1 to be the same as s2:

s1 = '\xd1\x98\xd1\x83\xd0\xbd'
s2 = u'\xd1\x98\xd1\x83\xd0\xbd'

s1 = s1.decode('unicode-escape')
Victor Castillo Torres
  • 10,581
  • 7
  • 40
  • 50