B
B
BnSmbr2020-09-11 16:57:44
Python
BnSmbr, 2020-09-11 16:57:44

Recoding in Python, how to write concisely?

There is a line: " \xd0\x94\xd0\xb0, \xd0\xbf\xd1\x82\xd0\xb8\xd1\x86\xd1\x8b \xd0\xbe\xd0\xbf\xd0\xb0\xd1\x81\ xd0\xbd\xd1\x8b "

When decrypting through the site: " Yes, birds are dangerous "

I am sincerely convinced that in python it is possible to convert this in one line so that a normal Russian text is written in the terminal, please help with the command. Preferably in one line

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PavelMos, 2020-09-11
@BnSmbr

decode is a built-in function, but it is not for a string, but for the bytes type, so you need to specify b' at the beginning

b'\xd0\x94\xd0\xb0, \xd0\xbf\xd1\x82\xd0\xb8\xd1\x86\xd1\x8b \xd0\xbe\xd0\xbf\xd0\xb0\xd1\x81\xd0\xbd\xd1\x8b "'.decode()
Out[106]: 'Да, птицы опасны "'

by default, it looks like utf-8 here, so the parameters in brackets can be omitted.

G
Gennady S, 2020-09-11
@gscraft

Where does such a line come from? It was supposed to do as you like as bits and immediately converted with decode () on arrival.

b'\xd0\x94\xd0\xb0, \xd0\xbf\xd1\x82\xd0\xb8\xd1\x86\xd1\x8b \xd0\xbe\xd0\xbf\xd0\xb0\xd1\x81\xd0\xbd\xd1\x8b'.decode()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question