Posted August 22, 2015
It's interesting to note that, in Python 3, if you get the encoding wrong, Python will complain *loudly*.
For example,
>>> x = bytes([128])
>>> x
b'\x80'
>>> x.decode('ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
Incidentally, I have had debian's 'reportbug' program fail in this manner when trying to read certain bug reports. (I don't know whether this bug has been fixed.)
For example,
>>> x = bytes([128])
>>> x
b'\x80'
>>> x.decode('ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
Incidentally, I have had debian's 'reportbug' program fail in this manner when trying to read certain bug reports. (I don't know whether this bug has been fixed.)