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.

3
  • Ooops, found the answer right here that solves the problem: stackoverflow.com/questions/11174790/… But why should I encode to Latin-1 when text is in Cyrillic? Or better, why doesn't s2.encode('windows-1251') work? Commented Jun 21, 2013 at 4:12
  • That looks to me to be UTF-8, u'\u0458\u0443\u043d', јун. Commented Jun 21, 2013 at 4:18
  • This is already posted in Stackoverflow. Check here: stackoverflow.com/questions/11174790/… Commented Jun 21, 2013 at 4:19

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.