PEP 358 and operations on bytes

John Machin sjmachin at
Wed Oct 4 05:05:41 CEST 2006

Gerrit Holl wrote:
> Hi,
> In Python 3, reading from a file gives bytes rather than characters.
> Some operations currently performed on strings also make sense when
> performed on bytes, either if it's binary data or if it's text of
> unknown or mixed encoding. Those include of course slicing and other
> operators that exist in lists, but also other operations that aren't
> currently defined in PEP 358, like:
>     - str methods endswith, find, partition, replace, split(lines),
>       startswith,
>     - Regular expressions
> I think those can be useful on a bytes type. Perhaps bytes and str could
> share a common parent class? They certainly share a lot of properties
> and possible operations one might want to perform.

I look at it this way::
Processing text? Use unicode.
Binary structures and file I/O, interfacing to 8-bit-wide channels? Use
Nostalgic for confused mixed-use? Don't upgrade.

IMHO, core dev time would be better used on:

* making /relevant/ modules (e.g. struct) work with bytes -- this topic
is not mentioned in the PEP.
* ensuring it covers everything that array.array('B', ...) does.
* being able to initialise a bytes array to (typically) all zeroes
without having to instantiate an  initialiser e.g. record =
bytes(size=996, fill=0) instead of record = bytes(996 * [0])

than on starts(ends)with etc, and regexes.


More information about the Python-list mailing list