[Python-3000] Immutable bytes type and dbm modules

Jim Jewett jimjjewett at gmail.com
Tue Aug 7 23:03:37 CEST 2007


On 8/7/07, Guido van Rossum <guido at python.org> wrote:
> On 8/7/07, Collin Winter <collinw at gmail.com> wrote:
> > Could someone please explain to me the conceptual difference between
> > array.array('B'), bytes(), buffer objects and simple lists of
> > integers? I'm confused about when I should use which.

[bytes and array.array are similar, but bytes have extra methods and a
literal notation]

[buffer is read-only to your code, but may not be immutable]

> Lists of integers don't have the property that the other three share
> which is that their C representation is a contiguous array of bytes
> (char* in C). This representation is important because to do efficient
> I/O in C you need char*.

This sounds almost as if they were all interchangable implementations
of the same interface, and you should choose based on quality of
implementation.

If the need for immutable isn't worth a distinct type, I'm not sure
why "I want it to be fast" is worth two (or three) extra types,
distinguished by the equivalent of cursor isolation level.

FWLIW, I think the migration path for the existing three types makes
sense, but I would like b" ... " to be an immutable bytes object, and
bytes(" ... ") to be the constructor for something that can mutate.

-jJ


More information about the Python-3000 mailing list