Avatar ·

Python: 'Charmap' Codec Can 'Canomet Decode by 0x98

📁 итератор, python, ошибка, пример, работа

Good afteoon I read the UTF8 file and display to the console. When trying to derive the letter "" and "" an error arises:

  file  "" I: \ programfile \ anaconda \ lib \ encodings \ cp1251.py "" , line  15 ,  in  decode    retu  codecs.charmap_decode ( 'Charmap'  codec can  '' 't Decode by 0x98 in the Position 1: Character Maps to & LT; Undefined & gt;      

is played on this example:

  test_text_1 =  "" Task \ n ""  test_text_2 =  file =  open  ( '' tamp.txt ', ,  'w' , encoding =  'utf-8' ) file.write (test_text_1) file.write (test_text_2) file.close () text =  open  ( 'TEMP.TXT' ,  'rb' )   for  byte_code  in  text:   print  (byte_code.strip ())  test_text = byte_code.Decode ( 'cp1251' )   print  (test_text.strip ())     

the first word is displayed normally, and on the second - an error. I just can’t find a way to overcome the problem.

upd: Apparently I described the problem too widely, I am corrected:

how to convert "and" "from UTF-8 to CP1251? It works, but for "" "and" " - no.

code:

  byte1 =  '` ` .encode ( 'utf-8' ) byte2 =  '' and ' .encode (' utf-8 ')   print  (Byte1, Byte2) test1 = byte1.decode ( 'cp1251' )   print  (test1) test2 = byte2.decode ( 'CP1251' )   print  (test2)