[Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]

Terry Reedy tjreedy at udel.edu
Tue Jan 7 23:38:42 CET 2014


On 1/7/2014 2:43 PM, Ethan Furman 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)'

To me, a major feature of Python is that it a) has more than one basic 
structure type (versus just strings or symbolic expressions) but b) is 
conservative in its multiplicity. It is not minimal, but it is 
minimalistic. It took over a decade for Guido to agree that Python 
should have separate built-in bool and set classes instead of just using 
ints as bools and tuples, lists, and dicts as sets, or using imported 
classes for either.

The above describes a minor variation on bytes and seems to me to be a 
classic case for subclassing, whether in Python for ease or C for speed, 
in an imported module. The result could be kept private or made public 
as you wish. Yes, the minor differences would be important to you, the 
author of the subclass, but that is always the motivation for subclassing.

One of the major advances in Python was to make it possible (in 2.2) to 
subclass the basic builtin structure classes. It seems to me that 
subclasses that work in multiple versions of Python, such as are already 
being used, are the appropriate solution to the specialized problems 
that people have with the Python string builtins.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list