Newbie question about text encoding
Marko Rauhamaa
marko at pacujo.net
Sat Mar 7 11:48:24 EST 2015
Mark Lawrence <breamoreboy at yahoo.co.uk>:
> On 07/03/2015 16:25, Marko Rauhamaa wrote:
>> Here's an example:
>>
>> b = b'\x80'
>>
>> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping
>> from str objects to bytes objects.
>
> Python 2 might, Python 3 doesn't.
Python 3.3.2 (default, Dec 4 2014, 12:49:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\x80'.decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0:
invalid start byte
Marko
More information about the Python-list
mailing list