[Python-ideas] a new bytestring type?

Mark Janssen dreamingforward at gmail.com
Mon Jan 6 01:39:53 CET 2014


> As anyone who has worked with Python 3 and low-level protocols knows, Python
> 3 has no 'bytestring' type.  It has immutable and mutable versions of arrays
> of integers, otherwise known as 'bytes' and 'bytearray'.

"arrays of integers"?  You mean, unsigned short ints?  There's an
important difference.  One references an abstraction, and one
references a concrete machine type.

The other consideration is knowing what you mean by "string", if you
mean something to be interpreted textually, then the convention is to
use unsigned chars to document your intentions, which "technically" is
the same (as far as memory layout is concerned).  (I say "technically"
because there is some space reserved for endian-ness which can change
the bit ordering.)

> How many would be interested in having a 'bytestring'?
>
> What do you see as the distinguishing characteristics?

What it *should* have is a bytes-type, which is a raw, 8-bit type
which may or may not printable on the screen with quotation marks.
Different subtypes, >>>class Text(bytes) can interpret those bytes as
they want (as a text string for example, with or without formatting
awareness for control codes.  Otherwise File(bytes) can interpret
those bytes as binary data, so as to write to the file system without
any transformation of the codes (i.e. raw).

I'm afraid this reply may not be up to the standards of the list, but
hopefully has some useful data that has gone without good
understanding.

MarkJ


More information about the Python-ideas mailing list