[Tutor] encodings

Denis Dzyubenko shad@mail.kubtelecom.ru
Fri Jun 13 15:57:02 2003


Hello, all

How can I convert some text from one encoding to another? For example,
I have text in koi8-r (default charset on my linux-system) and I need
to convert this text to cp1251 before sending into socket.
I try this:

('txt' variable contains russian text in koi8-r charset)

>>> txt.encode("cp1251")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/encodings/cp1251.py", line 18, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeError: ASCII decoding error: ordinal not in range(128)

What should I do ?

Python 2.2, as you see, on Debian 3.0r0
-- 
Denis.