I have a line like this: b'\\u0417\\u0434\\u0440\\u0430'
How to decode it? Utf-8 encoding.

PS this is a string, not bytes

Closed due to the fact that the subject matter of the question is not clear to the party PashaPash 27 Apr '17 at 19:53 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • @TimurValiyev there is simply how to make a "word" from the storok to make a transfer to the type bytes. But my utf code is not represented in bytes, but in the string is Andrei Antipov
  • maybe here ? The guys here already faced with this - TimurVI
  • @Andrey Antipov, this is not UTF-8, but UTF-16. Feel the difference. - 0andriy
  • 2
    What is the type of your "string"? Show: print(type(data)) and print(ascii(data)) . Where did the data come from? (if this is part of json, then you don't need to parse your hands, use json-parser) - jfs

1 answer 1

As noted in the commentary Timur Valiev , the solution of a similar problem is described here . In your case, do this:

 >>>> string = "b'\\u0417\\u0434\\u0440\\u0430'" >>>> print(string[2:-1].encode('utf-8').decode('unicode-escape')) Здра