D
D
Dmitry Gulakov2021-07-29 01:25:56
Python
Dmitry Gulakov, 2021-07-29 01:25:56

How do encodings work?

I can't figure out how coding works in python. The function decode(bytes_)throws an error, trying to decode cp1251, I set encoding='utf-8', the same error, and in the same file cp1251. From a psycho, I import the utf_8 library directly and use decode from there. Same error, absolutely. Sometimes I manage to somehow magically make it work, but this time the error comes out when I try to print the already decoded text using print, and the error is the same, only it is displayed on the stack, as from the print (text) function. python 3.7
decode(bytes_, encoding='utf-8')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Shevkunov, 2021-07-29
@danila763

text = b'\xef\xf0\xe8\xe2\xe5\xf2'
print(text.decode('cp1251'))
text - text encoded cp1251
decode - specify what encoding the text is in, convert to a readable encoding (utf-8 like)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question