Python Forum
How to convert unicode to koi8-r?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert unicode to koi8-r?
#1
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:
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'?
Reply


Messages In This Thread
How to convert unicode to koi8-r? - by AlekseyPython - Feb-21-2019, 10:51 AM
RE: How to convert unicode to koi8-r? - by snippsat - Feb-21-2019, 04:18 PM
RE: How to convert unicode to koi8-r? - by DeaD_EyE - Mar-04-2019, 08:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert Int Value bigger 256 to Unicode lastyle 4 2,782 Mar-19-2020, 11:48 AM
Last Post: lastyle
  clean unicode string to contain only characters from some unicode blocks gmarcon 2 4,011 Nov-23-2018, 09:17 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020