[Tutor] encodings

Denis Dzyubenko shad@mail.kubtelecom.ru
Fri Jun 13 18:38:02 2003


On Fri, 13 Jun 2003 23:05:53 +0200,
 Magnus Lyck(ML) wrote to me:

ML> First, you need to DECODE the koi8-r to the common format that all
ML> encodings understand: Unicode!

I tried this too! It doesn't help:

>>> s =3D u"abc=C1=C2=D7"
>>> s.encode('cp1251')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.1/encodings/cp1251.py", line 18, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeError: charmap encoding error: character maps to <undefined>

ML> txt.decode('koi8-r').encode('cp1251')

>>> txt.decode('koi8-r')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: decode

ML> Of course, in general txt.decode(x).encode(y) only works if
ML> both encodings x and y support the same characters. You can

they support.
iconv encode/decode text without problems.

--=20
Denis.

=F5=D0=C1=CB=D5=CA, =E7=CF=D3=D0=CF=C4=C9, =C4=D5=DB=D5 =C5=C7=CF!...