How to turn a string into a list of integers?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Sep 6 07:17:43 EDT 2014


Peter Otten wrote:

> Steven D'Aprano wrote:
> 
>>>>>> import sys
>>>>>> sys.getdefaultencoding()
>>> 'ascii'
>> 
>> That's technically known as a "lie", since if it were *really* ASCII it
>> would refuse to deal with characters with the high-bit set. But it
>> doesn't, it treats them in an unpredictable and implementation-dependent
>> manner.
> 
> It's not a lie, it just doesn't control the unicode-to-bytes conversion
> when printing:

That's not what I'm referring to. I'm referring to this:

py> s
'\xff'


There is no such ASCII character (or code point, to steal terminology from
Unicode). ASCII is a 7-bit encoding, and includes 128 characters, with
ordinal values 0 through 127. Once you accept arbitrary bytes 128 through
255, it's no longer ASCII, it's ASCII plus undefined stuff.

(Historical note: the committee that designed ASCII *explicitly* rejected
making it an 8-bit code. They also considered, but rejected, using a 6-bit
code with a "shift" function.)


-- 
Steven




More information about the Python-list mailing list