unicode and data strings

Fredrik Lundh fredrik at pythonware.com
Fri Jan 28 04:32:57 EST 2005


Laszlo Zsolt Nagy wrote:

> Now I installed Python 2.3.4 and wxPython 2.5.3 (with unicode support). I'm getting this 
> exception:
>
> exceptions.UnicodeDecodeError:'ascii' codec can't decode byte 0x91 in position 0: ordinal not in 
> range(128)

>From where?

Can you include a "print repr()" of the string you're trying to convert, and
enough code from your script to be able to reproduce the problem?

> The I tried this:
>
> >>>'\x91'.decode('utf8')
> UnicodeDecodeError: 'utf8' codec can't decode byte 0x91 in position 0: unexpected code byte
> >>>'\x91'.encode('utf8')
>
> Here is the question: I would like to use simple binary data strings (like an array of bytes).
> I do not care about encodings. How do I do that?

Unicode errors only appear if you're converting between "raw 8-bit data" and
Unicode strings (which contain Unicode characters, not bytes or integers).  You
cannot do that without caring about encodings...

</F> 






More information about the Python-list mailing list