[Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]
Ethan Furman
ethan at stoneleaf.us
Tue Jan 7 21:58:40 CET 2014
On 01/07/2014 12:49 PM, Guido van Rossum wrote:
> On Tue, Jan 7, 2014 at 9:43 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> My vision for a bytestring type (more refined):
>>
>> - made up of single bytes in the range 0 - 255 (no unicode anywhere)
>>
>> - indexing returns a bytestring of length 1, not an integer (as bytes
>> does)
>>
>> - `bytestring(7)` either fails, or returns 'bytestring('\x07')' not
>> 'bytestring(0, 0, 0, 0, 0, 0, 0)'
>
> It sounds like you are just unhappy with some of the behavior of the
> bytes object. I agree that these two behaviors are suboptimal, but it
> is just too late to change them, and it's not enough to add a new type
> -- not by a long shot. The constructor behavior can be changed using a
> custom factory function. The indexing behavior, unfortunately, needs
> to be dealt with by changing b[i] into b[i:i+1] everywhere.
Of course I'm unhappy with it, it doesn't behave the way I think it should, and it's not consistent.
The reason I started the thread was to hopefully gather others requirements to have a truly distinct and useful new
type. Doesn't seem to have happened, though. :(
Is it too late to change the repr for bytes? I can't think of anywhere else in the stdlib where what you see is not
what you get:
--> [0, 1, 2]
[0, 1, 2]
--> [0, 1, 2][1]
1
--> {'this':'that', 'these':'those'}
{'this': 'that', 'these': 'those'}
--> {'this':'that', 'these':'those'}['these']
'those'
--> 'abcdef'
'abcdef'
--> 'abcdef'[3]
'd'
But of course with bytes:
--> b'abcdef'
b'abcdef'
--> b'abcdef'[3]
100
--
~Ethan~
More information about the Python-ideas
mailing list