S
S
Sasha Filinsky2021-08-02 18:00:00
Python
Sasha Filinsky, 2021-08-02 18:00:00

How to decode unicode to UTF-8 python3?

How do I decode unicode to UTF-8?
I can’t understand in any way, can I write a ready-made method or function?

PS I have UNICODE written in the string and I need to decrypt it in UTF-8.
In python 2 there was a decode function, but in 3 I did not see anything like that.
Unicode is written as plain text to a variable.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MinTnt, 2021-08-02
@MinTnt

s = '''\u0412\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043e\u0444\u0438\u0441\u044b:
- \u041a\u0438\u0435\u0432, \u041a\u0438\u0435\u0432 \u0443\u043b.\u041c\u0435\u0442\u0430\u043b\u043b\u0438\u0441\u0442\u043e\u0432'''

print(s.encode().decode())

S
Sergo Zar, 2021-08-02
@Sergomen

import codecs
text = "твой текст"
decoded = codecs.decode("кодировка", text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question