unicode codecs

"Martin v. Löwis" martin at v.loewis.de
Mon Feb 9 23:36:02 CET 2004


Ivan Voras wrote:
> When concatenating strings (actually, a constant and a string...) i get 
> the following error:
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 1: 
> ordinal not in range(128)
> 
> Now I don't think either string is unicode

This statement must be false. When concatenating two byte strings, no
codec is ever used. So, either
1. one of the strings is a Unicode objects, or
2. you are not performing concatenation, or you get the exception
    from an operation that is not concatenation, or
3. you are not getting this exception.

Most likely, it is 1)

> The point is: I know all values will fit
> in a particular code page (iso-8859-2), so how do I change the 'ascii' 
> codec in the above error into something that will work?

Explicitly encode the Unicode string in your concatenation as
iso-8859-2.

Regards,
Martin




More information about the Python-list mailing list