Feb-21-2019, 10:51 AM
(This post was last modified: Feb-21-2019, 10:51 AM by AlekseyPython.)
Python 3.7.2
I write data to the database, so I want to write lines in a format that has a low weight. One character of the Russian language in utf8 occupies 2 bytes, and in the koi8-r encoding only 1 byte (I am only interested in Russian and English alphabets, the other characters can be ignored).
When in Python I convert the English- Russian string to koi8-r, I get a strange sequence:
How I can convert data in 'small format'?
I write data to the database, so I want to write lines in a format that has a low weight. One character of the Russian language in utf8 occupies 2 bytes, and in the koi8-r encoding only 1 byte (I am only interested in Russian and English alphabets, the other characters can be ignored).
When in Python I convert the English- Russian string to koi8-r, I get a strange sequence:
utf = 'My string, Моя строка' koi = utf.encode(encoding='koi8-r', errors='ignore')
Output:koi bytes: b'My string, \\xed\\xcf\\xd1 \\xd3\\xd4\\xd2\\xcf\\xcb\\xc1'
When I write these values to the database, I get write- errors.How I can convert data in 'small format'?