Here is the option to cut:

string="ʾÓÙÕ‗Ý¹Ú Ë‗ÕÝ¯Û ´│õÔ│±ÝÞÚ ¯¸Þ¨¾ÔÓ¸ õÙ ¾Ý│‗Óþ¾ ÐÔ│µ│±‗³ ´ÕÙ■±‗Û│Ô1 °‗." puts string.encode("cp850").force_encoding("windows-1251").encode("utf-8") 

Tell me, please, how to implement it in python, preferably python3?

  • If suddenly this is a string from the database (mysql), then it is better to properly configure the connection settings for this database - andreymal
  • And if this is just a line from a neighboring question, then it is better to give your own lines, because the answer for your specific task may not be suitable - andreymal
  • Line: x = 'Å “ñú“ “ó¬á ¬ Start' 'Start' 'Ó Ó Ó Ó. HUMAN RIGHTS ÔÔ¿¿¿¿ß «« «´´´´Ù« «¿Ô ®Ñ®ßÔó¿´ "" ½½º "Ôѽ´ ¡Ñ ÑÑÔÓÒ¯Ôß´. ' As far as I understand this is cp850, it is advisable to bring it to cp866 or cp1251. These are lines of the windows system log where the IBM, IIB application is written. Only his log is displayed in "crooked boxes", other applications write the information correctly. - Kirode

2 answers 2

 >>> string = "ʾÓÙÕ‗Ý¹Ú Ë‗ÕÝ¯Û ´│õÔ│±ÝÞÚ ¯¸Þ¨¾ÔÓ¸ õÙ ¾Ý│‗Óþ¾ ÐÔ│µ│±‗³ ´ÕÙ■±‗Û│Ô1 °‗." >>> string.encode('cp850').decode('cp1251') 'Туалетный Утенок підвісний очищувач дл унітазу Свіжість пелюстків1 шт.' 

UPD: for another line from the comment:

 >>> x = 'Å«ñú«Ô«ó¬á ¬ Start ßÑÓóÑÓá ¿¡ÔÑúÓᵿ¿. æÑÓóÑÓ ¿¡ÔÑúÓᵿ¿ ß«í¿ÓáÑÔß´ óÙ»«½¡¿Ôý ñÑ®ßÔó¿Ñ. äÑ®ßÔó¿´ »«½ýº«óáÔѽ´ ¡Ñ ÔÓÑíÒ¯Ôß´.' >>> x.encode('cp850').decode('cp866') 'Подготовка к Start сервера интеграции. Сервер интеграции собирается выполнить действие. Действия пользователя не требуются.' 

True, it may be better to consider the full path from getting a line to using it (where, how and why) for a more accurate answer.

  • string1 = "Ë‗ÕÝ Û Û │ Ô│ Ô│ Ô│ ± ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ Ù Ù Ù ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ ¸Þ¨¾ÔÓ¸ │ │ │ │ │ │ │ │ │ │ │ print (string1.encode ('cp850'). decode ('cp1251')) UnicodeEncodeError: 'charmap' codec can’t get coding in 0-8: character maps to <undefined> - Kirode
  • If it’s in the Windows console, then it’s tricky to print there and I don’t know how to do it - andreymal
  • Thank. It works through the interpreter, but an error comes out through the windows console, the ruby ​​script at the same time prints to the console normally, so I'm trying to figure out how it works in python. And if you output to the file then there should be no problems? Problems only with the console? - Kirode
  • At the moment I am discussing the issue, if it is not possible to configure the program so that the information is output in a different encoding, then I will write a script that will take the information from the log and output it to the file or console while transcoding. - Kirode
  • In theory, only with the console, yes. It will be perfectly written to the file in utf-8 encoding automatically, and how to print correctly to the WIndows console, someone else can tell - andreymal

If I change the console encoding to cp866, then for output to the console, I had this option:

 print(user_input.encode('cp850').decode('cp866').encode('utf-8').decode('utf-8')) 

but the Ruby option works without changing the console encoding, so I’m trying to look for more options.

The option to cut, working without changing the encoding:

 puts string.encode("cp850").force_encoding("IBM866").encode("utf-8")