[Python-Dev] Re: adding a bytes sequence type to Python
Guido van Rossum
guido at python.org
Tue Aug 17 23:33:54 CEST 2004
> So, how will it be different from:
>
> from array import array
>
> def bytes(*initializer):
> return array('B',*initializer)
>
> Even if it's desirable for 'bytes' to be an actual type (e.g. subclassing
> ArrayType), it might help the definition process to describe the difference
> between the new type and a byte array.
Not a whole lot different, except for the ability to use a string as
alternate argument to the constructor, and the fact that it's going to
be an actual type, and that it should support the buffer API (which
array mysteriously doesn't?).
The string argument support may not even be necessary -- an
alternative way to spell that would be to let s.decode() return a
bytes object, which has the advantage of being explicit about the
encoding; there's even a base64 encoding already! But it would be a
bigger incompatibility, more likely to break existing code using
decode() and expecting to get a string.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list