[Python-Dev] adding a bytes sequence type to Python (original) (raw)

Skip Montanaro skip at pobox.com
Thu Aug 12 16:27:34 CEST 2004


Guido> Anyway, if we really do have enough use cases for byte array
Guido> literals, we might add them.  I still think that would be
Guido> confusing though, because byte arrays are most useful if they are
Guido> mutable: and then we'd have mutable literals -- blechhhh!

Today I can initialize mutable objects from immutable strings:

>>> print list("abc")
['a', 'b', 'c']
>>> print set("abc")
set(['a', 'c', 'b'])

I see no reason that mutable bytes objects couldn't be created from otherwise immutable sequences either. Would it be a problem to ensure that

a = b"abc"
b = b"abc"
print a is b

prints False?

The main difference as I see it is that byte literals would be completely devoid of any sort of interpretation as unicode sequences. It would be nice if this was possible:

# -*- coding: utf-8 -*-
b = b"รข"

though that would probably wreak havoc with editors and hex escapes would have to be used in most situations.

Skip



More information about the Python-Dev mailing list