osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Putting Unicode characters in JSON


On Fri, Mar 23, 2018 at 4:35 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Fri, 23 Mar 2018 12:05:34 +1100, Chris Angelico wrote:
>
>> Latin-1 is not "arbitrary bytes". It is a very specific encoding that
>> cannot decode every possible byte value.
>
> Yes it can.
>
> py> blob = bytes(range(256))
> py> len(blob)
> 256
> py> blob[45:55]
> b'-./0123456'
> py> s = blob.decode('latin1')
> py> len(s)
> 256
> py> s[45:55]
> '-./0123456'
>

That doesn't seem to be a strictly-correct Latin-1 decoder, then.
There are a number of unassigned byte values in ISO-8859-1.

ChrisA